Changeset 20:00a827356b07 in rrlib_xml


Ignore:
Timestamp:
27.12.2010 21:29:16 (9 years ago)
Author:
Jens Wettach <wettach@…>
Branch:
default
Phase:
public
Convert:
svn:3219ad6e-c0b7-4ac2-9554-e22e195eef7a/trunk@21
Message:

inhanced interface of <tXMLNode> and <tXMLDocument> for <rrlib::simvis3d::tScene>, adapted test program

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tXMLDocument.cpp

    r16 r20  
    8686} 
    8787 
    88 //tXMLDocument::tXMLDocument(const void *buffer, size_t size, bool validate) 
    89 //    : document(xmlReadMemory(reinterpret_cast<const char *>(buffer), size, "noname.xml", 0, validate ? XML_PARSE_DTDVALID : 0)), 
    90 //    root_node(0) 
    91 //{ 
    92 //  if (!this->document) 
    93 //  { 
    94 //    throw tXML2WrapperException("Could not parse XML from memory buffer `" + std::string(reinterpret_cast<const char *>(buffer)) + "'!"); 
    95 //  } 
    96 //} 
     88tXMLDocument::tXMLDocument(const void *buffer, size_t size, bool validate) 
     89    : document(xmlReadMemory(reinterpret_cast<const char *>(buffer), size, "noname.xml", 0, validate ? XML_PARSE_DTDVALID : 0)), 
     90    root_node(reinterpret_cast<tXMLNode *>(xmlDocGetRootElement(this->document))) 
     91{ 
     92  if (!this->document) 
     93  { 
     94    throw tXML2WrapperException("Could not parse XML from memory buffer `" + std::string(reinterpret_cast<const char *>(buffer)) + "'!"); 
     95  } 
     96  tCleanupHandler::GetInstance(); 
     97} 
    9798 
    9899//---------------------------------------------------------------------- 
  • tXMLDocument.h

    r14 r20  
    112112  explicit tXMLDocument(const std::string &file_name, bool validate = true); 
    113113 
    114 //  tXMLDocument(const void *buffer, size_t size, bool validate = true); 
     114  /*! The ctor of tXMLDocument from a memory buffer 
     115   * 
     116   * This ctor reads and parses XML content given in a memory buffer into a XML DOM 
     117   * representation. 
     118   * If needed, the XML document is also validated using an included 
     119   * DTD specification. 
     120   * 
     121   * \exception tXML2WrapperException is thrown if the memory buffer could not be parsed 
     122   * 
     123   * \param buffer      Pointer to the memory buffer with XML content to be parsed 
     124   * \param size        Size of the memory buffer 
     125   * \param validate    Whether the validation should be processed or not 
     126   */ 
     127  explicit tXMLDocument(const void *buffer, size_t size, bool validate = true); 
    115128 
    116129  /*! The dtor of tXMLDocument 
  • tXMLNode.h

    r18 r20  
    730730  } 
    731731 
     732  /*! Get list of XML attributes of this node 
     733   * 
     734   * \returns the XML attribute list 
     735   */ 
     736  xmlAttrPtr GetAttributeList() const 
     737  { 
     738    return this->properties; 
     739  } 
     740 
    732741  /*! Set an XML attribute of this node 
    733742   * 
     
    809818  /*! Get a dump in form of xml code of the subtree starting at \a this 
    810819   * 
    811    * \param format   Set to true im the dumped text should be indented 
     820   * \param format   Set to true if the dumped text should be indented 
    812821   */ 
    813822  const std::string GetXMLDump(bool format = false) const; 
     823 
     824 
     825  /*! Get number of children of this XML node. 
     826   * 
     827   *  Counts children. 
     828   * 
     829   *  \returns number of children. 
     830   */ 
     831  size_t GetNumChildren() const 
     832  { 
     833    return std::distance(this->GetChildrenBegin(), this->GetChildrenEnd()); 
     834  } 
    814835 
    815836}; 
  • test/test_xml2_wrapper.cpp

    r17 r20  
    117117  document1.WriteToFile("test.xml"); 
    118118 
    119   tXMLDocument document2("test.xml", false); 
     119  tXMLDocument document2(std::string("test.xml"), false); 
    120120 
    121121  std::cout << "doc 2" << std::endl; 
    122122 
    123   std::cout << "Accessing node with content: " << document2.GetRootNode().GetXMLDump() << std::endl; 
     123  std::cout << "Accessing node with content: " << document2.GetRootNode().GetXMLDump() 
     124            << " and " << document2.GetRootNode().GetNumChildren() << " children." << std::endl; 
    124125 
    125126  std::cout << document2.GetRootNode().GetName() << std::endl; 
     
    177178 
    178179 
    179   std::cout << "doc 1: " << document1.GetRootNode().GetXMLDump() << std::endl; 
    180  
     180  std::cout << "doc 1: " << document1.GetRootNode().GetXMLDump() << std::endl 
     181            << " has " << document1.GetRootNode().GetNumChildren() << " children." << std::endl; 
    181182 
    182183  return EXIT_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.