You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Satishkumar <sa...@foxboro.com> on 2001/06/28 14:49:42 UTC

xerces parsing

Hi,
 I have a xml file like,

<Data>
   <Variable>
     <Name>Length</Name>
     <Value>10</Value>
   </Variable>
</Data>

I am trying to parse this and get the value of Name using JAXP calls. The
code snippet is as below.

      NodeList nList = ((Document)node).getElementsByTagName(Attr);
      if ((nList != null) && (nList.getLength()>0))
      {
         System.out.println("Length is : " +nList.getLength()) ;
         Node n = nList.item(0);
         System.out.println(n.getNodeName() + " : " + n.getNodeValue()) ;
      }

I am creating a Docbuilder and passing on the doc to the method containing
the above snip. I am getting the length of the node list as 1 and Node name
as Name. But the getNodeValue returns null. Am I missing something?

Thanks & Regards,
Satish

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: xerces parsing

Posted by "Srinivasan D." <ds...@india.hp.com>.
Yes, you should get the node values as node.getFirstChild().getNodeValue();

This is because, element values in a Document should be added as text nodes to
elements.
and getFirstChild() for your node named "Name" will return the textnode.

So change your code snippet to

node.getFirstChild().getNodeValue().




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org