Please find below some excerpts from the new sample that we have
added to Xerces-C. It illustrates how you can create a DOM tree
in memory. Note: It uses DOM Level 2 api's to create the
document node.
The next binary release of Xerces-C 1.1.0 will contain this sample.
If you need it today, then you could download the snapshot of the
repository and compile it.
We hope to publish the next binary release in about two weeks.
rahul
-----------------------------------------------------------------------
// The tree we create below is the same that the DOMParser would
// have created, except that no whitespace text nodes would be created.
// <company>
// <product>Xerces-C</product>
// <category idea='great'>XML Parsing Tools</category>
// <developedBy>Apache Software Foundation</developedBy>
// </company>
DOM_DOMImplementation impl;
DOM_Document doc = impl.createDocument(
0, // root element namespace URI.
"company", // root element name
DOM_DocumentType()); // document type object (DTD).
DOM_Element rootElem = doc.getDocumentElement();
DOM_Element prodElem = doc.createElement("product");
rootElem.appendChild(prodElem);
DOM_Text prodDataVal = doc.createTextNode("Xerces-C");
prodElem.appendChild(prodDataVal);
DOM_Element catElem = doc.createElement("category");
rootElem.appendChild(catElem);
catElem.setAttribute("idea", "great");
DOM_Text catDataVal = doc.createTextNode("XML Parsing Tools");
catElem.appendChild(catDataVal);
DOM_Element devByElem = doc.createElement("developedBy");
rootElem.appendChild(devByElem);
DOM_Text devByDataVal = doc.createTextNode("Apache Software Foundation");
devByElem.appendChild(devByDataVal);
//
// Now count the number of elements in the above DOM tree.
//
unsigned int elementCount = doc.getElementsByTagName("*").getLength();
cout << "The tree just created contains: " << elementCount
<< " elements." << endl;
-----------------------------------------------------------------------