[jdom-interest] XMLOutputter NPE

Wesley Biggs wbiggs at elite.com
Thu Aug 3 15:46:38 PDT 2000


Will,

The XML specification states that there should be no semantic difference
between
<tag></tag>
and
<tag />
So if you rely on that to indicate a null (and it's tempting, I've been down
that path) you're probably going to get thrown to the wolves on the whim of
whatever parser/outputter you choose.

What you're probably looking for is
<tag xsl:null="true" />

Which JDOM doesn't directly support (you have to define the XSL namespace,
etc.), but it at least gives you a clear and reliable semantic distinction
between null and empty.

Wes

-----Original Message-----
From: Will Glozer [mailto:will.glozer at jda.com]
Sent: Thursday, August 03, 2000 3:20 PM
To: 'jdom-interest at jdom.org'
Subject: [jdom-interest] XMLOutputter NPE


I'm just starting to use JDOM, so please forgive me in advance if this is
a known issue... I looked through the more recent logs and didn't see 
anything.

        XMLOutputter xmlOut = new XMLOutputter();

        Element e = new Element("test");
        Document doc = new Document(e);
        e.setText("");

        xmlOut.output(doc, System.out);

That code will throw a NullPointerException inside XMLOutputter.output
because
the contents of the Element is an empty string... The question I have is
whether
or not JDOM will ever be able to distinguish between empty,
String.equals(""), 
Element content and null, String == null, content.

I was able to do this with W3C DOM, so I'd like to see it in JDOM.  Perhaps
consider doing "<tag />" as null content and "<tag></tag>" as empty content?

Thanks,
Will
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com



More information about the jdom-interest mailing list