Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert an XMLElement to string in TinyXML2

In TinyXml 1 it was possible to convert a child element to a string using the << operator, e.g.

TiXmlElement * pxmlChild = pxmlParent->FirstChildElement( "child" );
std::stringstream ss;
ss << (*pxmlChild);

This doesn't appear possible in TinyXml2. How do you convert an element to an xml string in TinyXml2?

Edit: Specifically I'm after the xml, e.g. if the xml was:

<parent>
    <child>
        <value>abc</value>
    </child>
<parent>

I want the xml for the child element, e.g.

<child>
    <value>abc</value>
</child>
like image 969
snowdude Avatar asked Aug 13 '12 13:08

snowdude


2 Answers

Seems like Print isn't there any more but Accept works just as well:

XMLPrinter printer;
pxmlChild->Accept( &printer );
ss << printer.CStr();
like image 59
Adam Thomson Avatar answered Oct 14 '22 04:10

Adam Thomson


From the TinyXml2 community:

Printing (of a sub-node) is in a utility function:

XMLPrinter printer;
pxmlChild->Print( &printer );
ss << printer.CStr();
like image 20
snowdude Avatar answered Oct 14 '22 03:10

snowdude