Changeset 14:901108bdcd47 in rrlib_xml


Ignore:
Timestamp:
23.12.2010 02:47:12 (9 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Convert:
svn:3219ad6e-c0b7-4ac2-9554-e22e195eef7a/trunk@15
Message:

Using the underlying linked list instead of an own children vector (that was really buggy).

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • tXMLDocument.cpp

    r12 r14  
    8383} 
    8484 
     85//tXMLDocument::tXMLDocument(const void *buffer, size_t size, bool validate) 
     86//    : document(xmlReadMemory(reinterpret_cast<const char *>(buffer), size, "noname.xml", 0, validate ? XML_PARSE_DTDVALID : 0)), 
     87//    root_node(0) 
     88//{ 
     89//  if (!this->document) 
     90//  { 
     91//    throw tXML2WrapperException("Could not parse XML from memory buffer `" + std::string(reinterpret_cast<const char *>(buffer)) + "'!"); 
     92//  } 
     93//} 
     94 
    8595//---------------------------------------------------------------------- 
    8696// tXMLDocument destructor 
     
    95105// tXMLDocument GetRootNode 
    96106//---------------------------------------------------------------------- 
    97 tXMLNode &tXMLDocument::GetRootNode() const 
     107tXMLNode &tXMLDocument::GetRootNode() 
    98108{ 
    99109  if (!this->root_node) 
     
    119129  } 
    120130  this->root_node = new tXMLNode(xmlNewNode(0, reinterpret_cast<const xmlChar *>(name.c_str()))); 
    121   xmlDocSetRootElement(this->document, this->root_node->data->node); 
     131  xmlDocSetRootElement(this->document, this->root_node->node); 
    122132  return *this->root_node; 
    123133} 
  • tXMLDocument.h

    r12 r14  
    112112  explicit tXMLDocument(const std::string &file_name, bool validate = true); 
    113113 
     114//  tXMLDocument(const void *buffer, size_t size, bool validate = true); 
     115 
    114116  /*! The dtor of tXMLDocument 
    115117   */ 
     
    123125   * \returns A reference to the root node 
    124126   */ 
    125   tXMLNode &GetRootNode() const; 
     127  tXMLNode &GetRootNode(); 
     128 
     129  inline const tXMLNode &GetRootNode() const 
     130  { 
     131    return const_cast<const tXMLDocument *>(this)->GetRootNode(); 
     132  } 
    126133 
    127134  /*! Add a root node to a new document in DOM representation 
  • tXMLNode.cpp

    r12 r14  
    3333// External includes (system with <>, local with "") 
    3434//---------------------------------------------------------------------- 
     35#include <cstring> 
     36 
     37//---------------------------------------------------------------------- 
     38// Internal includes with "" 
     39//---------------------------------------------------------------------- 
     40 
     41//---------------------------------------------------------------------- 
     42// Debugging 
     43//---------------------------------------------------------------------- 
    3544#include <cassert> 
    3645 
    3746//---------------------------------------------------------------------- 
    38 // Internal includes with "" 
    39 //---------------------------------------------------------------------- 
    40  
    41 //---------------------------------------------------------------------- 
    42 // Debugging 
    43 //---------------------------------------------------------------------- 
    44  
    45 //---------------------------------------------------------------------- 
    4647// Namespace usage 
    4748//---------------------------------------------------------------------- 
     
    6162 
    6263//---------------------------------------------------------------------- 
    63 // tXMLNode::tData constructors 
    64 //---------------------------------------------------------------------- 
    65 tXMLNode::tData::tData(xmlNodePtr node) 
    66     : ref_counter(1), 
    67     node(node), 
    68     name(0), 
    69     children(0), 
     64// tXMLNode constructors 
     65//---------------------------------------------------------------------- 
     66tXMLNode::tXMLNode(xmlNodePtr node) 
     67    : node(node), 
    7068    text_content(0) 
    7169{ 
     
    7876} 
    7977 
    80 //---------------------------------------------------------------------- 
    81 // tXMLNode::tData destructor 
    82 //---------------------------------------------------------------------- 
    83 tXMLNode::tData::~tData() 
    84 { 
    85   delete this->name; 
    86   delete this->children; 
     78tXMLNode::tXMLNode(const tXMLNode &other) 
     79    : node(other.node), 
     80    text_content(0) 
     81{} 
     82 
     83//---------------------------------------------------------------------- 
     84// tXMLNode destructor 
     85//---------------------------------------------------------------------- 
     86tXMLNode::~tXMLNode() 
     87{ 
    8788  delete this->text_content; 
    88 //  xmlUnlinkNode(this->node); 
    89 //  xmlFreeNode(this->node); 
    90 } 
    91  
    92 //---------------------------------------------------------------------- 
    93 // tXMLNode constructors 
    94 //---------------------------------------------------------------------- 
    95 tXMLNode::tXMLNode(xmlNodePtr node) 
    96     : data(new tData(node)) 
    97 {} 
    98  
    99 tXMLNode::tXMLNode(const tXMLNode &other) 
    100     : data(other.data) 
    101 { 
    102   this->data->ref_counter++; 
    103 } 
    104  
    105 //---------------------------------------------------------------------- 
    106 // tXMLNode destructor 
    107 //---------------------------------------------------------------------- 
    108 tXMLNode::~tXMLNode() 
    109 { 
    110   if (--this->data->ref_counter == 0) 
    111   { 
    112     delete this->data; 
    113   } 
     89} 
     90 
     91//---------------------------------------------------------------------- 
     92// tXMLNode operator = 
     93//---------------------------------------------------------------------- 
     94const tXMLNode &tXMLNode::operator = (const tXMLNode & other) 
     95{ 
     96  this->node = other.node; 
     97  return *this; 
    11498} 
    11599 
     
    117101// tXMLNode GetName 
    118102//---------------------------------------------------------------------- 
    119 const std::string &tXMLNode::GetName() const 
    120 { 
    121   if (!this->data->name) 
    122   { 
    123     this->data->name = new std::string(reinterpret_cast<const char *>(this->data->node->name)); 
    124   } 
    125   return *this->data->name; 
    126 } 
    127  
    128 //---------------------------------------------------------------------- 
    129 // tXMLNode GetChildren 
    130 //---------------------------------------------------------------------- 
    131 const std::vector<tXMLNode> &tXMLNode::GetChildren() const 
    132 { 
    133   if (!this->data->children) 
    134   { 
    135     this->data->children = new std::vector<tXMLNode>(); 
    136     for (xmlNodePtr child_node = this->data->node->children; child_node; child_node = child_node->next) 
     103const std::string tXMLNode::GetName() const 
     104{ 
     105  return reinterpret_cast<const char *>(this->node->name); 
     106} 
     107 
     108//---------------------------------------------------------------------- 
     109// tXMLNode AddChildNode 
     110//---------------------------------------------------------------------- 
     111tXMLNode tXMLNode::AddChildNode(const std::string &name) 
     112{ 
     113  if (this->HasTextContent()) 
     114  { 
     115    throw tXML2WrapperException("Tried to add a structural child to a node that already has text content!"); 
     116  } 
     117  return xmlNewChild(this->node, 0, reinterpret_cast<const xmlChar*>(name.c_str()), 0); 
     118} 
     119 
     120tXMLNode tXMLNode::AddChildNode(const tXMLNode &node) 
     121{ 
     122  xmlNodePtr child = node.node; 
     123  if (child->doc != this->node->doc) 
     124  { 
     125    child = xmlDocCopyNode(child, this->node->doc, 1); 
     126  } 
     127  xmlAddChild(this->node, child); 
     128  return child; 
     129} 
     130 
     131//---------------------------------------------------------------------- 
     132// tXMLNode RemoveChildNode 
     133//---------------------------------------------------------------------- 
     134void tXMLNode::RemoveChildNode(tXMLNode &node) 
     135{ 
     136  xmlNodePtr child_node = 0; 
     137  for (child_node = this->node->children; child_node && child_node != node.node; child_node = child_node->next); 
     138  if (!child_node) 
     139  { 
     140    throw tXML2WrapperException("Given node is not a child of this."); 
     141  } 
     142  xmlUnlinkNode(child_node); 
     143  xmlFreeNode(child_node); 
     144} 
     145 
     146//---------------------------------------------------------------------- 
     147// tXMLNode AddSibling 
     148//---------------------------------------------------------------------- 
     149tXMLNode tXMLNode::AddSibling(const tXMLNode &node) 
     150{ 
     151  assert(*this != node); 
     152  xmlNodePtr sibling = node.node; 
     153  if (sibling->doc != this->node->doc) 
     154  { 
     155    sibling = xmlDocCopyNode(sibling, this->node->doc, 1); 
     156  } 
     157  xmlAddNextSibling(this->node, sibling); 
     158  return sibling; 
     159} 
     160 
     161//---------------------------------------------------------------------- 
     162// tXMLNode HasTextContent 
     163//---------------------------------------------------------------------- 
     164const bool tXMLNode::HasTextContent() const 
     165{ 
     166  for (xmlNodePtr child_node = this->node->children; child_node; child_node = child_node->next) 
     167  { 
     168    if (xmlNodeIsText(child_node)) 
    137169    { 
    138       if (child_node->type == XML_ELEMENT_NODE) 
     170      xmlChar *text_content = xmlNodeGetContent(this->node); 
     171      if (this->text_content && std::strncmp(reinterpret_cast<const char *>(text_content), this->text_content->c_str(), this->text_content->length()) != 0) 
    139172      { 
    140         this->data->children->push_back(tXMLNode(child_node)); 
     173        delete this->text_content; 
     174        this->text_content = 0; 
    141175      } 
     176      if (!this->text_content) 
     177      { 
     178        this->text_content = new std::string(reinterpret_cast<const char *>(text_content)); 
     179      } 
     180      xmlFree(text_content); 
    142181    } 
    143182  } 
    144   return *this->data->children; 
    145 } 
    146  
    147 //---------------------------------------------------------------------- 
    148 // tXMLNode AddChildNode 
    149 //---------------------------------------------------------------------- 
    150 tXMLNode &tXMLNode::AddChildNode(const std::string &name) 
    151 { 
    152   if (this->HasTextContent()) 
    153   { 
    154     throw tXML2WrapperException("Tried to add a structural child to a node that already has text content!"); 
    155   } 
    156   xmlNodePtr child_node = xmlNewChild(this->data->node, 0, reinterpret_cast<const xmlChar*>(name.c_str()), 0); 
    157   this->GetChildren(); 
    158   this->data->children->push_back(tXMLNode(child_node)); 
    159   return this->data->children->back(); 
    160 } 
    161  
    162 //---------------------------------------------------------------------- 
    163 // tXMLNode RemoveChildNode 
    164 //---------------------------------------------------------------------- 
    165 void tXMLNode::RemoveChildNode(tXMLNode &node) 
    166 { 
    167   this->GetChildren(); 
    168   std::vector<tXMLNode>::iterator child_node = std::find(this->data->children->begin(), this->data->children->end(), node); 
    169   if (child_node == this->data->children->end()) 
    170   { 
    171     throw tXML2WrapperException("Given node is not a child of this."); 
    172   } 
    173   xmlUnlinkNode(child_node->data->node); 
    174   xmlFreeNode(child_node->data->node); 
    175   this->data->children->erase(child_node); 
    176 } 
    177  
    178 //---------------------------------------------------------------------- 
    179 // tXMLNode HasTextContent 
    180 //---------------------------------------------------------------------- 
    181 const bool tXMLNode::HasTextContent() const 
    182 { 
    183   if (!this->data->text_content) 
    184   { 
    185     for (xmlNodePtr child_node = this->data->node->children; child_node; child_node = child_node->next) 
    186     { 
    187       if (xmlNodeIsText(child_node)) 
    188       { 
    189         xmlChar *text_content = xmlNodeGetContent(this->data->node); 
    190         this->data->text_content = new std::string(reinterpret_cast<const char *>(text_content)); 
    191         xmlFree(text_content); 
    192       } 
    193     } 
    194   } 
    195   return this->data->text_content != 0; 
     183  return this->text_content != 0; 
    196184} 
    197185 
     
    205193    throw tXML2WrapperException("This node does not have any text content!"); 
    206194  } 
    207   return *this->data->text_content; 
     195  return *this->text_content; 
    208196} 
    209197 
     
    213201void tXMLNode::SetTextContent(const std::string &content) 
    214202{ 
    215   this->GetChildren(); 
    216   if (!this->data->children->empty()) 
     203  if (this->HasChildren()) 
    217204  { 
    218205    throw tXML2WrapperException("Tried to set text content in a node that already has structural children!"); 
    219206  } 
    220207  this->RemoveTextContent(); 
    221   xmlNodeAddContentLen(this->data->node, reinterpret_cast<const xmlChar *>(content.c_str()), content.length()); 
     208  xmlNodeAddContentLen(this->node, reinterpret_cast<const xmlChar *>(content.c_str()), content.length()); 
    222209} 
    223210 
     
    228215{ 
    229216  std::vector<xmlNodePtr> text_nodes; 
    230   for (xmlNodePtr child_node = this->data->node->children; child_node; child_node = child_node->next) 
     217  for (xmlNodePtr child_node = this->node->children; child_node; child_node = child_node->next) 
    231218  { 
    232219    if (xmlNodeIsText(child_node)) 
     
    240227    xmlFreeNode(*it); 
    241228  } 
    242   delete this->data->text_content; 
    243   this->data->text_content = 0; 
     229  delete this->text_content; 
     230  this->text_content = 0; 
    244231} 
    245232 
     
    253240    if (create) 
    254241    { 
    255       xmlNewProp(this->data->node, reinterpret_cast<const xmlChar *>(name.c_str()), reinterpret_cast<const xmlChar *>(value.c_str())); 
     242      xmlNewProp(this->node, reinterpret_cast<const xmlChar *>(name.c_str()), reinterpret_cast<const xmlChar *>(value.c_str())); 
    256243      return; 
    257244    } 
    258245    throw tXML2WrapperException("Attribute `" + name + "' does not exist in this node and creation was disabled!"); 
    259246  } 
    260   xmlSetProp(this->data->node, reinterpret_cast<const xmlChar *>(name.c_str()), reinterpret_cast<const xmlChar *>(value.c_str())); 
    261 } 
     247  xmlSetProp(this->node, reinterpret_cast<const xmlChar *>(name.c_str()), reinterpret_cast<const xmlChar *>(value.c_str())); 
     248} 
  • tXMLNode.h

    r12 r14  
    6464// Debugging 
    6565//---------------------------------------------------------------------- 
     66#include <cassert> 
    6667 
    6768//---------------------------------------------------------------------- 
     
    9192{ 
    9293  friend class tXMLDocument; 
    93  
    94   struct tData 
    95   { 
    96     unsigned int ref_counter; 
    97     xmlNodePtr node; 
    98     mutable std::string *name; 
    99     mutable std::vector<tXMLNode> *children; 
    100     mutable std::string *text_content; 
    101     tData(xmlNodePtr node); 
    102     ~tData(); 
    103   }; 
    104  
    105   tData *data; 
     94  friend class tXMLNodeSiblingIterator; 
     95 
     96  xmlNodePtr node; 
     97  mutable std::string *text_content; 
    10698 
    10799  /*! The ctor of tXMLNode 
     
    155147  tXMLNode(const tXMLNode &other); 
    156148 
    157   /*! The dtor of tXMLNode 
    158    */ 
    159149  ~tXMLNode(); 
    160150 
     151  const tXMLNode &operator = (const tXMLNode &other); 
     152 
    161153  /*! Comparison of XML node objects for find algorithm 
    162154   * 
     
    165157   * \returns Whether the two nodes are the same or not 
    166158   */ 
    167   bool operator == (const tXMLNode &other) 
    168   { 
    169     return this->data == other.data; 
     159  inline bool operator == (const tXMLNode &other) const 
     160  { 
     161    return this->node == other.node; 
     162  } 
     163 
     164  /*! Comparison of XML node objects for find algorithm 
     165   * 
     166   * \param other   The other node to compare to this one 
     167   * 
     168   * \returns Whether the two nodes are the same or not 
     169   */ 
     170  inline bool operator != (const tXMLNode &other) const 
     171  { 
     172    return this->node != other.node; 
    170173  } 
    171174 
     
    177180   * \returns A reference to the node's name 
    178181   */ 
    179   const std::string &GetName() const; 
    180  
    181   /*! Get the children of this node 
    182    * 
    183    * Within the DOM tree, each node can have a list of children. Access 
    184    * to this list is provided by this method. The internal vector the 
    185    * method returns a reference to is not created before the first call 
    186    * to this method (lazy evaluation) 
    187    * 
    188    * \returns A reference to the node's vector containing its children 
    189    */ 
    190   const std::vector<tXMLNode> &GetChildren() const; 
     182  const std::string GetName() const; 
     183 
     184  inline const bool HasChildren() const 
     185  { 
     186    return this->node->children != 0 && this->node->children->type == XML_ELEMENT_NODE; 
     187  } 
     188 
     189  inline tXMLNode GetFirstChild() 
     190  { 
     191    assert(this->node->children && this->node->children->type == XML_ELEMENT_NODE); 
     192    return this->node->children; 
     193  } 
     194 
     195  inline const tXMLNode GetFirstChild() const 
     196  { 
     197    return const_cast<tXMLNode *>(this)->GetFirstChild(); 
     198  } 
    191199 
    192200  /*! Add a child to this node 
     
    206214   * \returns A reference to the newly created node 
    207215   */ 
    208   tXMLNode &AddChildNode(const std::string &name); 
     216  tXMLNode AddChildNode(const std::string &name); 
     217 
     218  tXMLNode AddChildNode(const tXMLNode &node); 
    209219 
    210220  /*! Remove a structural child node 
     
    217227   */ 
    218228  void RemoveChildNode(tXMLNode &node); 
     229 
     230  inline const bool HasNextSibling() 
     231  { 
     232    return this->node->next != 0 && this->node->next->type == XML_ELEMENT_NODE; 
     233  } 
     234 
     235  inline tXMLNode GetNextSibling() 
     236  { 
     237    assert(this->node->next && this->node->next->type == XML_ELEMENT_NODE); 
     238    return this->node->next; 
     239  } 
     240 
     241  inline const tXMLNode GetNextSibling() const 
     242  { 
     243    return const_cast<tXMLNode *>(this)->GetNextSibling(); 
     244  } 
     245 
     246  tXMLNode AddSibling(const tXMLNode &node); 
    219247 
    220248  /*! Get whether this node has text content or not 
     
    264292  inline const bool HasAttribute(const std::string &name) const 
    265293  { 
    266     return xmlHasProp(this->data->node, reinterpret_cast<const xmlChar *>(name.c_str())) != 0; 
     294    return xmlHasProp(this->node, reinterpret_cast<const xmlChar *>(name.c_str())) != 0; 
    267295  } 
    268296 
     
    280308  inline const std::string GetStringAttribute(const std::string &name) const 
    281309  { 
    282     xmlChar *temp = xmlGetProp(this->data->node, reinterpret_cast<const xmlChar *>(name.c_str())); 
     310    xmlChar *temp = xmlGetProp(this->node, reinterpret_cast<const xmlChar *>(name.c_str())); 
    283311    if (!temp) 
    284312    { 
     
    515543  inline void RemoveAttribute(const std::string &name) 
    516544  { 
    517     xmlAttrPtr attr = xmlHasProp(this->data->node, reinterpret_cast<const xmlChar *>(name.c_str())); 
     545    xmlAttrPtr attr = xmlHasProp(this->node, reinterpret_cast<const xmlChar *>(name.c_str())); 
    518546    if (attr) 
    519547    { 
  • test/test.xml

    r8 r14  
    11<?xml version="1.0" encoding="UTF-8"?> 
    22<test prop_1="val" prop_2="true" prop_3="4.3" prop_4="123"> 
    3   <test1 prop_1="val_1" prop_2="true" prop_3="4.3">fn0rd&amp;&lt;bla</test1> 
     3  <test1 prop_1="val_1" prop_2="true" prop_3="4.3" prop_4="123"> 
     4    <test2 prop_1="val_2" prop_2="true" prop_3="4.3" prop_4="123"/> 
     5  </test1> 
    46</test> 
  • test/test_xml2_wrapper.cpp

    r12 r14  
    5656// Debugging 
    5757//---------------------------------------------------------------------- 
     58#include <cassert> 
    5859 
    5960//---------------------------------------------------------------------- 
     
    6970  root_node.SetAttribute("prop_3", 4.3); 
    7071  root_node.SetAttribute("prop_4", 123); 
    71   tXMLNode &node1 = root_node.AddChildNode("test1"); 
     72  tXMLNode node1 = root_node.AddChildNode("test1"); 
    7273  node1.SetAttribute("prop_1", "val_1"); 
    7374  node1.SetAttribute("prop_2", true); 
    7475  node1.SetAttribute("prop_3", 4.3); 
    7576  node1.SetAttribute("prop_4", 123); 
    76   node1.SetTextContent("blubb"); 
    77   std::cout << "Content = " << node1.GetTextContent() << std::endl; 
    78   node1.SetTextContent("fn0rd&<bla"); 
    79   std::cout << "Content = " << node1.GetTextContent() << std::endl; 
    80  
    81   node1.RemoveAttribute("prop_4"); 
    82 //  node1.RemoveTextContent(); 
    83  
    84 //  tXMLNode &node2 = node1.AddChildNode("test2"); 
     77//  node1.SetTextContent("blubb"); 
     78//  std::cout << "Content = " << node1.GetTextContent() << std::endl; 
     79//  node1.SetTextContent("fn0rd&<bla"); 
     80//  std::cout << "Content = " << node1.GetTextContent() << std::endl; 
     81// 
     82//  node1.RemoveAttribute("prop_4"); 
     83////  node1.RemoveTextContent(); 
     84// 
     85  tXMLNode node2 = node1.AddChildNode("test2"); 
    8586//  node2.SetAttribute("prop_1", "val_2"); 
    8687//  node2.SetAttribute("prop_2", true); 
     
    9091//  node1.RemoveChildNode(node2); 
    9192 
    92   document1.WriteToFile("test.xml"); 
     93  std::cout << document1.GetRootNode().GetName() << std::endl; 
     94  std::cout << document1.GetRootNode().GetStringAttribute("prop_1") << std::endl; 
     95  std::cout << document1.GetRootNode().GetBoolAttribute("prop_2") << std::endl; 
     96  std::cout << document1.GetRootNode().GetDoubleAttribute("prop_3") << std::endl; 
     97  std::cout << document1.GetRootNode().GetIntAttribute("prop_4") << std::endl; 
    9398 
    94   tXMLDocument document2("test.xml", false); 
     99//  for (tXMLNode::iterator it = document1.GetRootNode().GetChildrenBegin(); it != document1.GetRootNode().GetChildrenEnd(); ++it) 
     100//  { 
     101//    std::cout << it->GetName() << std::endl; 
     102//    std::cout << it->GetStringAttribute("prop_1") << std::endl; 
     103//    std::cout << it->GetBoolAttribute("prop_2") << std::endl; 
     104//    std::cout << it->GetDoubleAttribute("prop_3") << std::endl; 
     105//    if (it->HasAttribute("prop_4")) 
     106//    { 
     107//      std::cout << it->GetIntAttribute("prop_4") << std::endl; 
     108//    } 
     109//  } 
    95110 
    96   std::cout << document2.GetRootNode().GetName() << std::endl; 
    97   std::cout << document2.GetRootNode().GetStringAttribute("prop_1") << std::endl; 
    98   std::cout << document2.GetRootNode().GetBoolAttribute("prop_2") << std::endl; 
    99   std::cout << document2.GetRootNode().GetDoubleAttribute("prop_3") << std::endl; 
    100   std::cout << document2.GetRootNode().GetIntAttribute("prop_4") << std::endl; 
     111//  document1.WriteToFile("test.xml"); 
     112// 
     113//  tXMLDocument document2("test.xml", false); 
     114// 
     115//  std::cout << document2.GetRootNode().GetName() << std::endl; 
     116//  std::cout << document2.GetRootNode().GetStringAttribute("prop_1") << std::endl; 
     117//  std::cout << document2.GetRootNode().GetBoolAttribute("prop_2") << std::endl; 
     118//  std::cout << document2.GetRootNode().GetDoubleAttribute("prop_3") << std::endl; 
     119//  std::cout << document2.GetRootNode().GetIntAttribute("prop_4") << std::endl; 
     120// 
     121//  for (tXMLNode::const_iterator it = document2.GetRootNode().GetChildrenBegin(); it != document2.GetRootNode().GetChildrenEnd(); ++it) 
     122//  { 
     123//    std::cout << it->GetName() << std::endl; 
     124//    std::cout << it->GetStringAttribute("prop_1") << std::endl; 
     125//    std::cout << it->GetBoolAttribute("prop_2") << std::endl; 
     126//    std::cout << it->GetDoubleAttribute("prop_3") << std::endl; 
     127//    if (it->HasAttribute("prop_4")) 
     128//    { 
     129//      std::cout << it->GetIntAttribute("prop_4") << std::endl; 
     130//    } 
     131//  } 
    101132 
    102   for (std::vector<tXMLNode>::const_iterator it = document2.GetRootNode().GetChildren().begin(); it != document2.GetRootNode().GetChildren().end(); ++it) 
    103   { 
    104     std::cout << it->GetName() << std::endl; 
    105     std::cout << it->GetStringAttribute("prop_1") << std::endl; 
    106     std::cout << it->GetBoolAttribute("prop_2") << std::endl; 
    107     std::cout << it->GetDoubleAttribute("prop_3") << std::endl; 
    108     if (it->HasAttribute("prop_4")) 
    109     { 
    110       std::cout << it->GetIntAttribute("prop_4") << std::endl; 
    111     } 
    112   } 
     133 
     134//  tXMLDocument document3("include.xml", false); 
     135// 
     136//  std::cout << document3.GetRootNode().GetName() << std::endl; 
     137//  std::cout << document3.GetRootNode().GetStringAttribute("prop_1") << std::endl; 
     138//  std::cout << document3.GetRootNode().GetBoolAttribute("prop_2") << std::endl; 
     139//  std::cout << document3.GetRootNode().GetDoubleAttribute("prop_3") << std::endl; 
     140//  std::cout << document3.GetRootNode().GetIntAttribute("prop_4") << std::endl; 
     141// 
     142//  for (std::vector<tXMLNode>::const_iterator it = document3.GetRootNode().GetChildren().begin(); it != document3.GetRootNode().GetChildren().end(); ++it) 
     143//  { 
     144//    std::cout << it->GetName() << std::endl; 
     145//    std::cout << it->GetStringAttribute("prop_1") << std::endl; 
     146//    std::cout << it->GetBoolAttribute("prop_2") << std::endl; 
     147//    std::cout << it->GetDoubleAttribute("prop_3") << std::endl; 
     148//    if (it->HasAttribute("prop_4")) 
     149//    { 
     150//      std::cout << it->GetIntAttribute("prop_4") << std::endl; 
     151//    } 
     152//  } 
     153 
     154 
     155//  tXMLNode &insert_node = *document3.GetRootNode().GetChildren().begin(); 
     156// 
     157////  document2.GetRootNode().AddChildNode(insert_node); 
     158// 
     159// 
     160//  std::cout << "==============" << std::endl; 
     161// 
     162//  std::cout << document2.GetRootNode().GetName() << std::endl; 
     163//  std::cout << document2.GetRootNode().GetStringAttribute("prop_1") << std::endl; 
     164//  std::cout << document2.GetRootNode().GetBoolAttribute("prop_2") << std::endl; 
     165//  std::cout << document2.GetRootNode().GetDoubleAttribute("prop_3") << std::endl; 
     166//  std::cout << document2.GetRootNode().GetIntAttribute("prop_4") << std::endl; 
     167// 
     168//  for (std::vector<tXMLNode>::const_iterator it = document2.GetRootNode().GetChildren().begin(); it != document2.GetRootNode().GetChildren().end(); ++it) 
     169//  { 
     170//    std::cout << it->GetName() << std::endl; 
     171//    std::cout << it->GetStringAttribute("prop_1") << std::endl; 
     172//    std::cout << it->GetBoolAttribute("prop_2") << std::endl; 
     173//    std::cout << it->GetDoubleAttribute("prop_3") << std::endl; 
     174//    if (it->HasAttribute("prop_4")) 
     175//    { 
     176//      std::cout << it->GetIntAttribute("prop_4") << std::endl; 
     177//    } 
     178//  } 
     179 
    113180 
    114181  return EXIT_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.