I've been using Xerces-C DOM and have run into an issue when writing to an
XML file. Basically, to write the XML file, I build up a DOMDocument,
adding nodes and such. Once the document is complete, the DOMWriter is used
to write the node to a file. I have cases though, where I'll have a string
containing XML characters, and several levels of descendant nodes.
Essentially, I want to write the string directly to the file as a child
node.
For example, the code snippet below will create a new DOM element, add an
attribute, and add a child text node. My problem occurs when the XMLCh*
variable "content" is a string that looks something like this:
"<Child>Test Content</Child>"
the resulting XML file will have the XML format characters translated.
<Child>Test Content</Child>
So is it possible to write the above XML string as a Text node, while
retaining the XML formatting?
Thanks in advance,
Greg
//////Begin source code
//first, create a new dataitem element
DOMElement* dataitemElem = m_DOMDocument->createElement(
X("Construction") );
//create and set the type attribute
dataitemElem->setAttribute(X("Type"), type);
//create a child text node of the new dataitem element
DOMText* dataitemElemVal = m_DOMDocument->createTextNode(content);
dataitemElem->appendChild((DOMNode*)dataitemElemVal);
//append the new child element to the root element
DOMElement* rootElem = m_DOMDocument->getDocumentElement();
rootElem->appendChild(dataitemsElem);
///////End source code
--