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