  | |  | Problem: Retrieving Parsed Node Value | Problem: Retrieving Parsed Node Value 2004-03-01 - By Brian Culver
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body text="#000000" bgcolor="#ffffff"> I have a problem getting the value of a node. I am using the following code to iterate through an XML file<br> <br> <font color="#000099">import javax.net.ssl.HttpsURLConnection;<br> import java.net.*;<br> import java.io.*;<br> import org.apache.xerces.parsers.DOMParser;<br> import org.w3c.dom.*;<br> <br> <snip><br> <br> if (node.hasChildNodes()) { //#document<br> System.out.println(node.getNodeName());<br> NodeList children = node.getChildNodes(); //Search<br> <br> for (int j = 0; j < children.getLength(); j++) {<br> System.out.println(children.item(j).getNodeName() +<br>   ; ": " + children.item(j).getNodeValue());<br> }<br> }</font><br> <br> The XML file looks like:<br> <br> <font color="#000099"><?xml version="1.0" encoding="utf-8"?><br> <Search><br> <Count>10</Count><br> <HasMoreItems>1</HasMoreItems><br> <GrandTotal>15</GrandTotal><br> <PageNumber>1</PageNumber><br> </Search></font><br> <br> And my output looks somewhat like:<br> <br> <font color="#000099">Search<br> #text: <br> Count: null<br> #text: <br> HasMoreItems: null<br> #text: <br> GrandTotal: null<br> #text: <br> PageNumber: null<br> #text: </font><br> <br> My problem is that I cannot get the values ... for example, GrandTotal has a value of 15 ... but I get null instead.<br> <br> Any ideas or suggestions<br> <br> Thank you,<br> <br> Brian Culver<br> <br> </body> </html>
|
|
 |