You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Ragunath Marudhachalam <rm...@circuitvision.com> on 2002/04/24 18:21:46 UTC
Help me in stylesheet reference.... URGENT
Hello All,
Sorry for posting the same problem again and again. But i couldn't figure
out what i'm doing wrong. Could anyone suggest where i'm going wrong?
import org.w3c.dom.*;
import javax.xml.parsers.*;
import org.apache.xerces.parsers.*;
import org.apache.xml.serialize.*;
import java.io.*;
public class Testxsl {
public Testxsl(){
try
{
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document OutDocument = db.newDocument ();
Element OutRootElement = OutDocument.createElement ("cv");
OutDocument.appendChild(OutRootElement);
ProcessingInstruction pi =
OutDocument.createProcessingInstruction("xml-stylesheet",
"href=\"http://wsd-007:8080/instruction.xsl\" type=\"text/xsl\"");
System.out.println("pi " + pi.getData());
OutDocument.insertBefore(pi, OutDocument.getParentNode());
//OutDocument.appendChild(pi);
OutputFormat format = new OutputFormat(OutDocument);
StringWriter stringOut = new StringWriter();
XMLSerializer serial = new XMLSerializer(stringOut,
format);
serial.asDOMSerializer();
serial.serialize(OutDocument.getDocumentElement());
String str = stringOut.toString();
System.out.println("doc " + str);
}catch(Exception e){}
}
public static void main(String[] args){
new Testxsl();
}
}
This is the test class i'm using to create xml document and i'm trying to
add xsl reference to it. But it is not adding the reference to it and the
output i'm getting is like this.
<?xml version="1.0" encoding="UTF-8"?>
<cv/>
But i'm expecting a document like this.
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://wsd-007:8080/instruction.xsl"
type="text/xsl"?>
<cv/>
What should i do to make my document like this....
Thank you all for your time....
Ragu
CircuitVision
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Help me in stylesheet reference.... URGENT
Posted by Scott Vachalek <sc...@Integrisoft.COM>.
Hi Ragunath,
I think it's quite simple: first replace
serial.serialize(OutDocument.getDocumentElement());
with
serial.serialize(OutDocument);
since the PI is not a child of the <cv/> element. Then you will see the PI,
but it is in the wrong position. To fix this, change:
OutDocument.insertBefore(pi, OutDocument.getParentNode());
to
OutDocument.insertBefore(pi, OutDocument.getDocumentElement());
since getParentNode() on a Document returns "null".
Hope this helps,
Scott
----- Original Message -----
From: "Ragunath Marudhachalam" <rm...@circuitvision.com>
To: <xe...@xml.apache.org>
Sent: Wednesday, April 24, 2002 9:21 AM
Subject: Help me in stylesheet reference.... URGENT
> Hello All,
>
> Sorry for posting the same problem again and again. But i couldn't figure
> out what i'm doing wrong. Could anyone suggest where i'm going wrong?
>
>
> import org.w3c.dom.*;
> import javax.xml.parsers.*;
> import org.apache.xerces.parsers.*;
> import org.apache.xml.serialize.*;
> import java.io.*;
>
> public class Testxsl {
>
> public Testxsl(){
> try
> {
> DocumentBuilderFactory dbf =
> DocumentBuilderFactory.newInstance();
> DocumentBuilder db = dbf.newDocumentBuilder();
> Document OutDocument = db.newDocument ();
> Element OutRootElement = OutDocument.createElement ("cv");
> OutDocument.appendChild(OutRootElement);
> ProcessingInstruction pi =
> OutDocument.createProcessingInstruction("xml-stylesheet",
> "href=\"http://wsd-007:8080/instruction.xsl\" type=\"text/xsl\"");
> System.out.println("pi " + pi.getData());
> OutDocument.insertBefore(pi, OutDocument.getParentNode());
> //OutDocument.appendChild(pi);
> OutputFormat format = new OutputFormat(OutDocument);
> StringWriter stringOut = new StringWriter();
> XMLSerializer serial = new XMLSerializer(stringOut,
> format);
> serial.asDOMSerializer();
> serial.serialize(OutDocument.getDocumentElement());
> String str = stringOut.toString();
> System.out.println("doc " + str);
> }catch(Exception e){}
> }
> public static void main(String[] args){
> new Testxsl();
> }
> }
>
>
>
> This is the test class i'm using to create xml document and i'm trying to
> add xsl reference to it. But it is not adding the reference to it and the
> output i'm getting is like this.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <cv/>
>
> But i'm expecting a document like this.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-stylesheet href="http://wsd-007:8080/instruction.xsl"
> type="text/xsl"?>
> <cv/>
>
>
> What should i do to make my document like this....
>
> Thank you all for your time....
>
> Ragu
> CircuitVision
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org