[jdom-interest] Problem with getText() / jdom b9 rc2
Simon McLeish
s.mcleish at lse.ac.uk
Fri Apr 25 08:29:05 PDT 2003
Hi,
I've recently moved installed jdom b9 rc2 because I was experimenting
with schema validation, and even though the schema validates the
document OK, the previously working Element getText() call now returns
"Exception in thread "main" java.lang.NullPointerException" even though
the relevant element does contain text. I've tried replacing it with
getContent with an appropriate filter, but it still gives me the same
error. Can anyone suggest a fix? Turning off the validation also gives
the same error, which suggests I'm missing something really obvious.
The relevant code is:
SAXBuilder builder = new
SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
builder.setFeature ("http://xml.org/sax/features/validation", true);
builder.setFeature ("http://apache.org/xml/features/validation/schema",
true);
// Read the document (a config file)
Document doc = builder.build(in);
// Get the root element
Element root = doc.getRootElement();
// Load the hostname, port and handlers
Element portElt = root.getChild("port");
String port = portElt.getText(); <-- error thrown here, same occurs at
next getText() if comment this line
The document looks like:
<?xml version="1.0"?>
<rm_config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.angel.ac.uk/rm_config"
xsi:schemaLocation="http://www.angel.ac.uk/rm_config
http://www.angel.ac.uk/schemas/rm_config.xsd"
name="Angel">
(irrelevant content)
<host>bungo.lse.ac.uk</host>
<port type="unprotected">5557</port>
(more irrelevant content)
</rm_config>
More information about the jdom-interest
mailing list