W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2001

Re: XML & CreateProcessingInstruction

From: Joseph Kesselman <keshlam@us.ibm.com>
Date: Thu, 28 Jun 2001 11:22:56 -0400
To: "Jayashree Krishnamoorthy" <jayashree.krish@mphasis.com>
Cc: <www-dom@w3.org>
Message-ID: <OF2C2E3978.ED6C16FB-ON85256A79.0053D87F@pok.ibm.com>

>    Document doc =
(Document)Class.forName("org.apache.xerces.dom.DocumentImpl").newInstance
();

Don't do that; it's not only nonportable but isn't really supported.
Instead, obtain the DOMImplmentation obect (which currently does require a
nonportable step):
     DOMImplementation
domImpl=org.apache.xerces.dom.DOMImplementationImpl.getDOMImplementation();
and then use
     Document doc=domImpl.createDocument(...);
Note that createDocument forces you to create the root element.



Then, after you create the ProcessingInstruction node, remember to insert
or append it as a child of some other node; otherwise it won't be part of
your document tree. In this case, what you probably want to do is insert it
as a child of the Document node, before the Document Element:

     ProcessingInstruction myPI = doc.createProcessingInstruction
("xml-stylesheet"," type=\"text/xsl\"
href=\"http://localhost:8080/examples/jsp/XMLProject/quiz1_xsl.xsl\"");
     doc.insertBefore(myPI,doc.getDocumentElement());




______________________________________
Joe Kesselman  / IBM Research
Received on Thursday, 28 June 2001 11:23:40 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:48 GMT