Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#741 NullPointerException when transforming xml from a String

v9.0
closed
Michael Kay
5
2012-10-08
2007-11-27
nico_inria
No

If I want to transform a xml String, there will be a NullPointerException when creating object XdmNode :

String xmlContent = "<?xml version="1.0" encoding="UTF-8"?>
<network name="name" time-precision="4"/>"
StreamSource xml = new StreamSource(new StringReader(xmlContent));
Processor proc = new Processor(false);
XdmNode source = proc.newDocumentBuilder().build(xml);

because of those lines in net.sf.saxon.s9api.XdmNode constructor:

if (source.getSystemId() == null) {
source.setSystemId(baseURI.toString());
}

baseURI, which is an attribute of DocumentBuilder object, is almost always null, even when the xml source is a file. So it triggers a NullPointerException when source.getSystemId() is also null.

I have to add a default URI in my code :

net.sf.saxon.s9api.DocumentBuilder documentBuilder = proc.newDocumentBuilder();
try {
documentBuilder.setBaseURI(new URI("file://..."));
} catch (URISyntaxException ex) {
...
}
XdmNode source = documentBuilder.build(xml);

and that method setBaseURI() is not part of the Jaxp specification, so I have to specify documentBuilder object as instance of net.sf.saxon.s9api.DocumentBuilder

Discussion

  • Michael Kay
    Michael Kay
    2007-11-27

    Logged In: YES
    user_id=251681
    Originator: NO

    This is a duplicate of 1831265, for which a patch is available.