1

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?

2 Answers 2

4

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);
Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.