Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] a small bug, perhaps

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: dirk bergstrom <dirk AT juniper.net>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] a small bug, perhaps
  • Date: Fri, 14 Feb 2003 10:59:48 -0800

i got the following error running 1.0d10:

java.lang.NullPointerException
at nu.xom.TextWriter.writeAttributeValue(TextWriter.java:171)
at nu.xom.Serializer.write(Serializer.java:224)
at nu.xom.Serializer.write(Serializer.java:477)
at nu.xom.Serializer.write(Serializer.java:164)
at net.juniper.rli.xml.XMLifier.renderToStream(XMLifier.java:71)

i had set preserveBaseUri(true) on the serializer, but hadn't actually
defined a base uri (the perils of cut-n-paste). it's my fault for asking
the library to do the impossible, but i don't think it should throw an NPE.
writeAttributeValue is looking for the length of the baseURI string...

the problem is here:

// check to see if we need an xml:base attribute
if (preserveBaseURI) {
if (element.getAttribute("base",
"http://www.w3.org/XML/1998/namespace";) == null) {
ParentNode elemParent = element.getParent();
if (elemParent == null || elemParent instanceof Document
|| !element.getBaseURI().equals(elemParent.getBaseURI())) {
escaper.writeMarkup(' ');
escaper.writeMarkup("xml:base=\"");
>>>> escaper.writeAttributeValue(element.getBaseURI());
escaper.writeMarkup("\"");
}
}
}

----------------

public void writeAttributeValue(String s) throws IOException {
for (int i=0; i < s.length(); i++) {
writeAttributeValue(s.charAt(i));
}
}


here's the relevant part of my code:

public static void renderToStream(Object thing, OutputStream out)
throws IOException {
Document doc = render(thing);
Serializer serializer = new Serializer(out, "ISO-8859-1");
serializer.setIndent(2);
serializer.setMaxLength(64);
serializer.preserveBaseURI(true);
serializer.write(doc);
serializer.flush();
}


thanks.

--
Dirk Bergstrom dirk AT juniper.net
_____________________________________________
Juniper Networks Inc., Computer Geek
Tel: 408.745.3182 Fax: 408.745.8905



  • [XOM-interest] a small bug, perhaps, dirk bergstrom, 02/14/2003

Archive powered by MHonArc 2.6.24.

Top of Page