943,829 Members | Top Members by Rank

Ad:
Nov 14th, 2008
0

Saxon's DocumentBuilder.build throws a NullPointer when passing a stream source

Expand Post »
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:

java Syntax (Toggle Plain Text)
  1.  
  2. // create a XSLT transformer
  3. XsltTransformer trans = comp.compile(new StreamSource(MyClass.getResourceAsStream(XSLT_FILE))).load();
  4.  
  5. // [...]
  6.  
  7. // sample XML to pass as parameter
  8. String str = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" +
  9. "<opsys:operatingSystems xmlns:opsys=\"http://osnews.pl/operating-systems\">\n" +
  10. " <opsys:operatingSystem id=\"1\">\n" +
  11. " <opsys:name>GNU/Linux</opsys:name>\n" +
  12. " <opsys:code>GNU</opsys:code>\n" +
  13. " </opsys:operatingSystem>\n" +
  14. " <opsys:operatingSystem id=\"2\">\n" +
  15. " <opsys:name>Microsoft</opsys:name>\n" +
  16. " <opsys:code>MSFT</opsys:code>\n" +
  17. " </opsys:operatingSystem>\n" +
  18. "</opsys:operatingSystems>";
  19.  
  20. ByteArrayInputStream byteStream = new ByteArrayInputStream(str.getBytes());
  21. StringReader reader = new StringReader(str);
  22.  
  23. SAXSource source = new SAXSource(new XMLFilterImpl(), new InputSource(reader));
  24.  
  25. // this throws a null pointer exception in build method
  26. XdmNode node = db.build(source);
  27.  
  28. // this works as intended
  29. // XdmNode node = db.build(
  30. // new File("test.xml"));
  31.  
  32. 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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
michux is offline Offline
3 posts
since Nov 2008
Nov 17th, 2008
0

Re: Saxon's DocumentBuilder.build throws a NullPointer when passing a stream source

OK, it was indeed a bug in saxon, I guess, solved in the latest release of Saxon: 9.1.0.3
Sorry for bugging anyone.
Borys
Reputation Points: 10
Solved Threads: 0
Newbie Poster
michux is offline Offline
3 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: Passing XML (node) parameters to XSLT in Saxon
Next Thread in XML, XSLT and XPATH Forum Timeline: XPath Div Node()??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC