I've modified the DOMPrint.cpp example to create a tree and then let the rest of the example print it out for me...
I have an issue with adding a PI to add a style-sheet reference to my output XML document. When I add it, the style-sheet reference comes after my document tag.
I'm trying to create an example with all types of nodes (That's why the CDATA for Son#3)
Anyway. I can't seem to figure out how to add the PI node to the DOM Document before defining the root element name "Family".
What am I missing?
Any help would be greatly appreciated.
Thanks,
Kevin
Here's the output from my modified DomPrint.cpp:
<!DOCTYPE Family SYSTEM "family.dtd">
<Family><?xml-stylesheet type="text/xsl/" href=""family.xsl"?><Mom>insertMomsName</Mom><Dad>insertDadsName</Dad><Children><!--List" my children here.--><Son age="4">firstSonsName</Son><Son age="2">secondSonsName</Son><Son age="6"><![CDATA[Montana&Dog]]></Son></Children></Family>
Here's the added code to my DOMPrint.cpp:
DOM_DOMImplementation impl;
DOM_DocumentType docType = impl.createDocumentType( "Family",
0, // "publicid",
"family.dtd" );
DOM_Document doc = impl.createDocument( 0, // "namespaceURI",
// root element namespace URI.
"Family", // root element name
docType );
DOM_Element rootElem = doc.getDocumentElement();
if (impl.hasFeature("version","1.0"))
cout << "Version 1.0" << endl;
else
cout << "Unknown Version" << endl;
// DOM_XMLDecl xmlDecl = DOM_XMLDecl();
// doc.importNode( xmlDecl, false );
/* DOM_XMLDecl xmlDecl = doc.createXMLDecl( "1.0",
* "UTF-8",
* "no" );
*/
// doc.appendChild( xmlDecl );
// Processing Instructions for XSL.
DOM_ProcessingInstruction pi = doc.createProcessingInstruction(
"xml-stylesheet",
"type=\"text/xsl/\" href="\"family.xsl\"");
rootElem.appendChild(pi);
// Mom element and text node.
DOM_Element momElem = doc.createElement("Mom");
rootElem.appendChild(momElem);
DOM_Text momDataVal = doc.createTextNode("insertMomsName");
momElem.appendChild(momDataVal);