0

I'm trying to create XML file with TinyXML2.

string _text = "<body><foo><foo2>text</foo2></foo></body>";
XMLElement *body = xmlDoc->NewElement("body");
body->SetText(_text.c_str());

Give me:

<body>
    &lt;body&gt;&lt;foo&gt;&lt;foo2&gt;text&lt;foo2/&gt;&lt;foo/&gt;&lt;body/&gt;
<body>

Is any way how to create empty element without top "body" and replace escape characters with <,>?

gomess
  • 83
  • 1
  • 8
  • escape charackters solved: XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE ) -> XMLDocument xmlDoc( false ); – gomess Apr 02 '17 at 13:39

1 Answers1

0

You've created a top level element <body> then added another <body> element, with child elements, below it. You can't create an 'empty' element but you can add your string directly into an empty document:

XMLDocument doc;
doc .Parse ("<body><foo><foo2>text</foo2></foo></body>");
stanthomas
  • 1,141
  • 10
  • 9