-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathElement.cpp
More file actions
42 lines (36 loc) · 727 Bytes
/
Element.cpp
File metadata and controls
42 lines (36 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// Created by Alone on 2022-8-8.
//
#include "Element.h"
using namespace xml;
#include<sstream>
using std::ostringstream;
string Element::_to_string()
{
if (m_name == "")
{
return "";
}
std::ostringstream os;
os << "<" << m_name;
for (auto &&[key, value]: m_attrs)
{
os << " " << key << "=\"" << value << "\"";
}
if (m_text.empty() && m_children.empty()) //判断是否为单元素
{
os << "/>";
return os.str();
}
os << ">";
os << m_text;
if (!m_children.empty())
{
for (auto &&child: m_children)
{
os << child._to_string();
}
}
os << "</" << m_name << ">";
return os.str();
}