[thelist] Java, JSP & XML
Jacques Capesius
jacques_capesius at cnt.com
Mon Mar 10 11:11:01 CST 2003
Hi Evolters,
I apologize in advance for the length of this post, but I wanna put all
necessary information for you wizards to do your magic :-)
Anyway, I thought I had the org.w3c.dom stuff figured out, but I have an XML
document that I'm trying to manipulate, and the problem I'm having is:
whenever I try to get the values contained in the nodes, I get returned a
null value. I'm not quite sure why this is happening, and I thought someone
out there could spot what I was doing wrong and let me know.
Here's the XML document....
<PSQ PSQID="7" PartnerID="CNT">
<PSQ_Name>Sarfaraz Test PSQ (SQL Server)</PSQ_Name>
<questions>
<question questionID="31" question_type="select" sortID="1" PSQID="7" >
<question_name>Pick a package or sample quote</question_name>
<answers>
<answer answerID="25" sortID="1" >Local STD</answer>
<answer answerID="26" sortID="2" >Local HA</answer>
</answers>
<validation_rules></validation_rules>
</question>
</questions>
</PSQ>
==========================================================
Here's the JSP (java) code I'm using to try and display the contents of the
<question_name> and <answer> tags...
NodeList nl1 = psq.getElementsByTagName("question");
for (int i=0;i<nl1.getLength();i++)
{
NodeList cl = nl1.item(i).getChildNodes();
out.println(cl.item(0).getNodeName() + " ");
out.println(cl.item(0).getNodeType() + " ");
out.println(cl.item(0).getNodeValue() + "<br>"); // the problematic
line
NodeList al = cl.item(1).getChildNodes();
for (int j=0;j<al.getLength();j++)
{
out.println(al.item(0).getNodeName() + " ");
out.println(al.item(0).getNodeType() + " ");
out.println(al.item(0).getNodeValue() + "<br>"); // the
problematic line
}
}
===========================================================
and the output...
question_name 1 null
answer 1 null
answer 1 null
does anybody know what I'm doing wrong, and why the getNodeValue() command
is displaying null instead of the contents of the tag?
Thanks a million for reading this, and for whatever help any of you can
give.
-jacques :)
More information about the thelist
mailing list