Aha. Try replacing the last two lines with:
m_Doc.insertBefore(domDecl, m_RootElement);
>From left to right, this means, "In the document's (m_Doc) node hierarchy,
insert the XMLDecl (domDecl) before the document root element
(m_rootElement)."
If you create a DOM_Node that doesn't actually refer to a node object
(created with one of the DOM_Document create...() members), it's treated as
a null node. An understanding of this concept is fundamental to using
Xerces: as a rule, you can't just construct objects and use them; you have
to explicitly create them with a create() function. Reading and fully
understanding http://xml.apache.org/xerces-c/program.html#ObjMemMgmt will
save you many headaches.
The insertBefore() documentation stipulates that when insertBefore is given
a null node for the second parameter, the node specified in the first
parameter is inserted at the end of the owner's list of children. In your
code, child is a null node, so
m_RootElement.insertBefore(dom_Decl,child);
is equivalent to
m_RootElement.insertBefore(dom_Decl,null);
In other words, it's a request to insert the XMLDecl at the end of
<Scanner>'s list of children. Hence the output you received.
-----Original Message-----
From: Chaim Koshizky [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 25, 2001 10:14 AM
To: '[EMAIL PROTECTED]'
Subject: RE: DOMPrint: Declaration and Document Type
Here is the code i use
m_Doc = m_Impl.createDocument(0, "Scanner" , DOM_DocumentType());
DOM_XMLDecl domDecl = m_Doc.createXMLDecl("1.0", "iso-8859-1" , "yes" );
m_RootElement = m_Doc.getDocumentElement();
DOM_Node child ;
m_RootElement.insertBefore(domDecl,child);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]