How to create CDATA with XmlTree

This feels like a pretty straightforward question, but for the life of me I can’t create an XML Object with CDATA.

I’ve been using:

XmlTree Scene("Scene", "");
XmlTree cdata("cdata", "");
cdata.setValue("This is a test.");

And the XML tree returned is:

<?xml version="1.0" encoding="utf-8"?>


which clearly has empty CDATA.

I even tried entering the entire xml file as a string:

std::string xmlString = "<Scene><![CDATA[ " + "this is a test" + " ]]></Scene>";
XmlTree Scene(xmlString);

But the XML this outputs lacks the CDATA entirely:

<?xml version="1.0" encoding="utf-8"?>
<Scene>this is a test</Scene>

How would I go about entering data into the CDATA field?

I took a look, but the only thing I found is the option XmlTree::ParseOptions that has a collapseCData flag, but it crashes when using ti to construct a XmlTreeNode with the “expected <” error from rapidxml.

That should be the expected behavior – the XmlTree::ParseOptions object is used for parsing an XML string in the constructor; if you pass that object, the constructor is expecting XML (not to /create/ XML). That’s why it crashes.

Unfortunatey, that also doesn’t resolve why we can’t write CDATA to the XML file.