| | |
Saxon's DocumentBuilder.build throws a NullPointer when passing a stream source
Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 3
Reputation:
Solved Threads: 0
In thread http://www.daniweb.com/forums/thread157149.html I was asking for different alternatives for passing a node as a parameter to an XSL stylesheet called from Java using saxon.
I set up on using the XdmNode object as a parameter for passing the parameter and here is a code extract:
Now as you can see in the above example, when I use a file as an input, the node is created fine and I can access the node with custom XML from the operatingSystems parameter in my XSLT (cool).
For some reason, when using a Source as an input for DocumentBuilder's build method, a NullPointerException is called.
The docs for DocumentBuilder: http://www.saxonica.com/documentatio...ansform.Source) claim that I should be using either SAXSource or JAXP source or DOMSource or PullSource. I tried a few but they all cause this exception to be thrown.
Any ideas before I start debugging saxon libraries?
I set up on using the XdmNode object as a parameter for passing the parameter and here is a code extract:
java Syntax (Toggle Plain Text)
// create a XSLT transformer XsltTransformer trans = comp.compile(new StreamSource(MyClass.getResourceAsStream(XSLT_FILE))).load(); // [...] // sample XML to pass as parameter String str = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" + "<opsys:operatingSystems xmlns:opsys=\"http://osnews.pl/operating-systems\">\n" + " <opsys:operatingSystem id=\"1\">\n" + " <opsys:name>GNU/Linux</opsys:name>\n" + " <opsys:code>GNU</opsys:code>\n" + " </opsys:operatingSystem>\n" + " <opsys:operatingSystem id=\"2\">\n" + " <opsys:name>Microsoft</opsys:name>\n" + " <opsys:code>MSFT</opsys:code>\n" + " </opsys:operatingSystem>\n" + "</opsys:operatingSystems>"; ByteArrayInputStream byteStream = new ByteArrayInputStream(str.getBytes()); StringReader reader = new StringReader(str); SAXSource source = new SAXSource(new XMLFilterImpl(), new InputSource(reader)); // this throws a null pointer exception in build method XdmNode node = db.build(source); // this works as intended // XdmNode node = db.build( // new File("test.xml")); trans.setParameter(new QName("operatingSystems"), node);
Now as you can see in the above example, when I use a file as an input, the node is created fine and I can access the node with custom XML from the operatingSystems parameter in my XSLT (cool).
For some reason, when using a Source as an input for DocumentBuilder's build method, a NullPointerException is called.
The docs for DocumentBuilder: http://www.saxonica.com/documentatio...ansform.Source) claim that I should be using either SAXSource or JAXP source or DOMSource or PullSource. I tried a few but they all cause this exception to be thrown.
Any ideas before I start debugging saxon libraries?
•
•
Join Date: Nov 2008
Posts: 3
Reputation:
Solved Threads: 0
Re: Saxon's DocumentBuilder.build throws a NullPointer when passing a stream source
0
#2 Nov 17th, 2008
![]() |
Other Threads in the XML, XSLT and XPATH Forum
- Previous Thread: passing xml document as input parameter to web service
- Next Thread: XPath Div Node()??
| Thread Tools | Search this Thread |
api blogger blogging code delete development dynamiccreationofnvariablesinxslt error firstthreecharacterofastringrequired flipbook gdata google html include java link linspire linux microsoft news node openoffice overwrite precedence programming rss standards swf template transform variable w3c web xml xmlnotloading xmlonserver xsl xslt





