1 | #include "xml_node.hpp" |
---|
2 | #include <boost_extract.hpp> |
---|
3 | |
---|
4 | namespace xios |
---|
5 | { |
---|
6 | namespace xml |
---|
7 | { |
---|
8 | /// ////////////////////// Définitions ////////////////////// /// |
---|
9 | |
---|
10 | StdString CXMLNode::RootName("simulation"); |
---|
11 | |
---|
12 | CXMLNode::CXMLNode(rapidxml::xml_node<char> * const root) |
---|
13 | : node(root) |
---|
14 | , level(0) |
---|
15 | { /* Ne rien faire de plus */ } |
---|
16 | |
---|
17 | CXMLNode::~CXMLNode(void) |
---|
18 | { /* Ne rien faire de plus */ } |
---|
19 | |
---|
20 | StdString CXMLNode::getElementName(void) const |
---|
21 | { |
---|
22 | return (this->node->name()); |
---|
23 | } |
---|
24 | |
---|
25 | bool CXMLNode::goToNextElement(void) |
---|
26 | { |
---|
27 | bool retvalue = false; |
---|
28 | for(rapidxml::xml_node<char> * nextElement = this->node->next_sibling(); |
---|
29 | ; nextElement = nextElement->next_sibling()) |
---|
30 | { |
---|
31 | if (nextElement == NULL) break; |
---|
32 | else if (nextElement->type() == rapidxml::node_element) |
---|
33 | { |
---|
34 | node = nextElement; |
---|
35 | return (!retvalue); |
---|
36 | } |
---|
37 | } |
---|
38 | return (retvalue); |
---|
39 | } |
---|
40 | |
---|
41 | bool CXMLNode::goToChildElement(void) |
---|
42 | { |
---|
43 | bool retvalue = false; |
---|
44 | rapidxml::xml_node<char> * nextElement = this->node->first_node(); |
---|
45 | if (nextElement != NULL) |
---|
46 | { |
---|
47 | for(;;nextElement = nextElement->next_sibling()) |
---|
48 | { |
---|
49 | if (nextElement == NULL) break; |
---|
50 | else if (nextElement->type() == rapidxml::node_element) |
---|
51 | { |
---|
52 | node = nextElement; |
---|
53 | level++; |
---|
54 | return (!retvalue); |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | return (retvalue); |
---|
59 | } |
---|
60 | |
---|
61 | bool CXMLNode::goToParentElement(void) |
---|
62 | { |
---|
63 | bool retvalue = false; |
---|
64 | if (!(this->getElementName().compare(CXMLNode::RootName)) || (level == 0)) |
---|
65 | return (retvalue); |
---|
66 | node = node->parent(); |
---|
67 | level--; |
---|
68 | return (!retvalue); |
---|
69 | } |
---|
70 | /* |
---|
71 | bool CXMLNode::getContent(StdString & content) |
---|
72 | { |
---|
73 | if (this->node->value_size() == 0) return (false); |
---|
74 | content.assign(this->node->value(), this->node->value_size()); |
---|
75 | return (true); |
---|
76 | } |
---|
77 | */ |
---|
78 | bool CXMLNode::getContent(StdString & content) |
---|
79 | { |
---|
80 | content="" ; |
---|
81 | bool retvalue = false; |
---|
82 | |
---|
83 | rapidxml::xml_node<char> * nextElement = this->node->first_node(); |
---|
84 | while (nextElement != NULL) |
---|
85 | { |
---|
86 | if (nextElement->type() == rapidxml::node_data) content=content+std::string(nextElement->value(),nextElement->value_size()); |
---|
87 | nextElement = nextElement->next_sibling(); |
---|
88 | } |
---|
89 | xios_replace_all(content,"\n"," ") ; |
---|
90 | content = xios_trim_copy(content); |
---|
91 | if (content.size()==0) return false ; |
---|
92 | else return true ; |
---|
93 | } |
---|
94 | |
---|
95 | const StdString & CXMLNode::GetRootName(void) |
---|
96 | { |
---|
97 | return (CXMLNode::RootName); |
---|
98 | } |
---|
99 | |
---|
100 | THashAttributes CXMLNode::getAttributes(void) const |
---|
101 | { |
---|
102 | THashAttributes attributes; |
---|
103 | rapidxml::xml_attribute<char> *currentAttr = NULL; |
---|
104 | |
---|
105 | if ((currentAttr = this->node->first_attribute()) != NULL) |
---|
106 | { |
---|
107 | do |
---|
108 | { |
---|
109 | attributes.insert(std::pair<StdString, StdString> |
---|
110 | (StdString(currentAttr->name()), |
---|
111 | StdString(currentAttr->value()))); |
---|
112 | } while ((currentAttr = currentAttr->next_attribute()) != NULL); |
---|
113 | } |
---|
114 | |
---|
115 | return (attributes) ; |
---|
116 | } |
---|
117 | |
---|
118 | }// namespace xml |
---|
119 | } // namespace xios |
---|