3

Is it possible to use TinyXML over a byte stream instead of a file?

Consider this code snippet:

TiXmlDocument doc("abc.xml");
if (!doc.LoadFile())
 return;
TiXmlHandle hDoc(&doc);

The above code snippet takes a file as input. How can I modify the code so that it accepts a byte stream? A sample code snippet would be great!

Vijay Mathew
  • 26,737
  • 4
  • 62
  • 93
webgenius
  • 856
  • 3
  • 13
  • 30

2 Answers2

3

Directly call TinyXmlDocument::Parse with the NULL terminated byte stream as the first argument. (See the implementation of TinyXmlDocument::LoadFile on how to call this function).

Vijay Mathew
  • 26,737
  • 4
  • 62
  • 93
1

After compiling TinyXML with STL support you can use the >> operator defined in the TiXmlNode base class:

std::istream& operator>> (std::istream & in, TiXmlNode & base)  

And as a working example:

std::istream & stream = /*your stream here*/;
TiXmlDocument xmlDoc;
stream >> xmlDoc;

Reference from the TinyXML documentation:

TinyXML can be compiled to use or not use STL. When using STL, TinyXML uses the std::string class, and fully supports std::istream, std::ostream, operator<<, and operator>>. (...) Use the compile time define: TIXML_USE_STL

Dean Mark
  • 71
  • 1
  • 6