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 Brian Culver <br...@codecountry.com> on 2004/03/01 23:26:02 UTC
Problem: Retrieving Parsed Node Value
I have a problem getting the value of a node. I am using the following
code to iterate through an XML file
import javax.net.ssl.HttpsURLConnection;
import java.net.*;
import java.io.*;
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.*;
<snip>
if (node.hasChildNodes()) { //#document
System.out.println(node.getNodeName());
NodeList children = node.getChildNodes(); //Search
for (int j = 0; j < children.getLength(); j++) {
System.out.println(children.item(j).getNodeName() +
": " + children.item(j).getNodeValue());
}
}
The XML file looks like:
<?xml version="1.0" encoding="utf-8"?>
<Search>
<Count>10</Count>
<HasMoreItems>1</HasMoreItems>
<GrandTotal>15</GrandTotal>
<PageNumber>1</PageNumber>
</Search>
And my output looks somewhat like:
Search
#text:
Count: null
#text:
HasMoreItems: null
#text:
GrandTotal: null
#text:
PageNumber: null
#text:
My problem is that I cannot get the values ... for example, GrandTotal
has a value of 15 ... but I get null instead.
Any ideas or suggestions
Thank you,
Brian Culver
Re: Problem: Retrieving Parsed Node Value
Posted by Neil Delima <nd...@ca.ibm.com>.
Hi Brian,
For Element nodes, getNodeValue returns null [1]. You will need to invoke
getNodeValue on the Element node's Text child.
Neil.
[1]
http://www.w3.org/TR/2004/PR-DOM-Level-3-Core-20040205/core.html#ID-F68D080
Brian Culver
<brian@codecountr
y.com> To
xerces-j-user@xml.apache.org
03/01/2004 05:26 cc
PM
Subject
Problem: Retrieving Parsed Node
Please respond to Value
xerces-j-user
I have a problem getting the value of a node. I am using the following
code to iterate through an XML file
import javax.net.ssl.HttpsURLConnection;
import java.net.*;
import java.io.*;
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.*;
<snip>
if (node.hasChildNodes()) { //#document
System.out.println(node.getNodeName());
NodeList children = node.getChildNodes(); //Search
for (int j = 0; j < children.getLength(); j++) {
System.out.println(children.item(j).getNodeName() +
": " + children.item(j).getNodeValue());
}
}
The XML file looks like:
<?xml version="1.0" encoding="utf-8"?>
<Search>
<Count>10</Count>
<HasMoreItems>1</HasMoreItems>
<GrandTotal>15</GrandTotal>
<PageNumber>1</PageNumber>
</Search>
And my output looks somewhat like:
Search
#text:
Count: null
#text:
HasMoreItems: null
#text:
GrandTotal: null
#text:
PageNumber: null
#text:
My problem is that I cannot get the values ... for example, GrandTotal has
a value of 15 ... but I get null instead.
Any ideas or suggestions
Thank you,
Brian Culver
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org