I have tried several ways to get the processing instructions in my XML
document:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="c:\abc.xslt">
<root>
</root>
with no success.
Method 1:
Document doc = new DocumentImpl();
ProcessingInstruction pi = doc.createProcessingInstruction
("xml-stylesheet", "type=text/xsl href=c:\\abc.xslt">
doc.appendChild(pi);
Element root = doc.createElement("root");
doc.appendChild(root);
Results:
The processing instruction does not appear in XML document.
Method 2:
Document doc = new DocumentImpl();
ProcessingInstruction pi = doc.createProcessingInstruction
("xml-stylesheet", "type=text/xsl href=c:\\abc.xslt">
Element root = doc.createElement("root");
Node node = doc.appendChild(root);
doc.insertBefore(pi, node);
Results:
The processing instruction does not appear in XML document.
Method 3:
Document doc = new DocumentImpl();
ProcessingInstruction pi = doc.createProcessingInstruction
("xml-stylesheet", "type=text/xsl href=c:\\abc.xslt">
Element root = doc.createElement("root");
Node node = doc.appendChild(root);
node.appendChild(pi);
Results:
The processing instruction appears after the root node.
Thanks.
Sally Nemes
EMMS Subsystem Development, IBM Software Group
Internet Mail: [EMAIL PROTECTED]
T/L 975-2872, External (561) 862-2872
IMAD 4181
8051 Congress Avenue
Boca Raton, Florida 33487
Andy Clark <[EMAIL PROTECTED]> on 10/09/2001 11:55:07 PM
Please respond to [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
cc:
Subject: Re: Help with Processing Instructions
Sally Nemes wrote:
> I am trying to generate an XML file that has 2 processing instructions
at
> the beginning of it
> before the root:
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-stylesheet type="text/xsl" href="c:\abc.xslt">
The first is not a processing instruction, even though it
looks like one. It is the XML Declaration as defined by
the XML specification. Therefore, you should not try to
create a processing instruction with the target name of
"xml".
> Document doc = new Document();
> ProcessingInstruction pi = doc.createProcessingInstruction
> ("xml-stylesheet", "type=text/xsl href=c:\abc.xslt">
> doc.appendChild(pi);
>
> Unfortunately I get errors using this method and several other ways that
I
> tried. Can you suggest a solution?
Please explain the error you are getting and include a
stack-trace if possible. Also, you need to escape the
backslash in your code (e.g. "c:\\abs.xslt").
--
Andy Clark * IBM, TRL - Japan * [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]