[219] | 1 | #include "xml_node.hpp" |
---|
[1363] | 2 | #include <boost/algorithm/string.hpp> |
---|
[219] | 3 | |
---|
[335] | 4 | namespace xios |
---|
[219] | 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) |
---|
[278] | 14 | , level(0) |
---|
[219] | 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(); |
---|
[1363] | 29 | ; nextElement = nextElement->next_sibling()) |
---|
[219] | 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 | { |
---|
[1367] | 47 | for(;;nextElement = nextElement->next_sibling()) |
---|
[219] | 48 | { |
---|
| 49 | if (nextElement == NULL) break; |
---|
| 50 | else if (nextElement->type() == rapidxml::node_element) |
---|
| 51 | { |
---|
[278] | 52 | node = nextElement; |
---|
| 53 | level++; |
---|
[219] | 54 | return (!retvalue); |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | return (retvalue); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | bool CXMLNode::goToParentElement(void) |
---|
| 62 | { |
---|
| 63 | bool retvalue = false; |
---|
[278] | 64 | if (!(this->getElementName().compare(CXMLNode::RootName)) || (level == 0)) |
---|
[219] | 65 | return (retvalue); |
---|
| 66 | node = node->parent(); |
---|
[278] | 67 | level--; |
---|
[219] | 68 | return (!retvalue); |
---|
| 69 | } |
---|
[1363] | 70 | /* |
---|
[274] | 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 | } |
---|
[1363] | 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 | boost::algorithm::replace_all(content,"\n"," ") ; |
---|
| 90 | boost::algorithm::trim(content) ; |
---|
| 91 | if (content.size()==0) return false ; |
---|
| 92 | else return true ; |
---|
| 93 | } |
---|
[274] | 94 | |
---|
[219] | 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 |
---|
[591] | 119 | } // namespace xios |
---|