开发者

tinyXML xml parsing with c++ without the xml file

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

char *开发者_Go百科 data = message.c_str ();

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


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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜