Arthur
Arthur

Reputation: 11

tinyXML xml parsing with c++ without the xml file

I am trying to parse xml from a message like this:

char * data = message.c_str ();

How can I create the xmlDoc with the string or a char array data, meaning without the xml file?

Upvotes: 1

Views: 1715

Answers (2)

Chris Morgan
Chris Morgan

Reputation: 2080

You could use the std::istream& operator >> (std::istream& in, TiXmlNode& base); function defined in tinyxml.h:

C++ style input:

based on std::istream operator>>

Reads XML from a stream, making it useful for network transmission. The tricky part is knowing when the XML document is complete, since there will almost certainly be other data in the stream. TinyXML will assume the XML data is complete after it reads the root element. Put another way, documents that are ill-constructed with more than one root element will not read correctly. Also note that operator>> is somewhat slower than Parse, due to both implementation of the STL and limitations of TinyXML.

Upvotes: 2

Bart
Bart

Reputation: 20028

I think you can do so via the Parse method in TiXmlDocument. So something like:

TiXmlDocument doc;
doc.Parse((const char*)data, 0, TIXML_ENCODING_UTF8);

Upvotes: 4

Related Questions