On Sun, 27 May 2001 [EMAIL PROTECTED] wrote:
> Hi there,
>
> I'm having a problem with the .getNodeValue() too.
>
<snip />
> System.out.println(indst.getChildNodes().item(0).getNodeName().toString());
> //Output = "Service"
> String service =
> indst.getChildNodes().item(0).getNodeValue().toString(); //Output =
> NullPointerException
> System.out.println("The value of the element node service " +
> service); // Never reached
>
> The Node is an ElementNode.
>
> XML file:
> <?xml version="1.0" encoding="UTF-8"?>
> <Indstillinger>
> <Service>aService</Service>
> </Indstillinger>
The text content of Element nodes is not stored as the node value of the
Element node, it is stored as Text node children of the Element. Calling
getNodeValue() on an Element node will always return null. In your
example, the text "aService" is found in
indst.getChildNodes().item(0).getFirstChild()
which is an instance of org.w3c.dom.Text
Ian
--
Ian Roberts, Software Engineer DecisionSoft Ltd.
Telephone: +44-1865-203192 http://www.decisionsoft.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]