Re: XML & CreateProcessingInstruction

>    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 UTC