Node.getNodeValue() problem 2003-10-20 - By Michael Ryan Bannon
Hello,
This might be just a stupid Java problem I'm overlooking.
The snippet below deals with a TEXT_NODE with a String value "and":
============================================ ...
// Output the value of a text node. // This should, and does, output "and". System.out.println(node.getNodeValue());
// Test the node. if (node.getNodeValue() == "and") System.out.println("it worked");
.. ============================================
Now, I've confirmed that it's a text node before the snippet. The first println outputs "and". However, the "if" statement is false, so I never see "it worked". How is this possible?
This seems so trivial...what am I missing?
Thanks in advance,
Ryan <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1264" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2>Hello,</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>This might be just a stupid Java problem I'm overlooking.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>The snippet below deals with a TEXT_NODE with a String value "and"</FONT><FONT face=Arial size=2>:</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>============================================</FONT></DIV> <DIV><FONT face=Arial size=2>...</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>// Output the value of a text node.</FONT></DIV> <DIV><FONT face=Arial size=2>// This should, and does, output "and".</FONT></DIV> <DIV><FONT face=Arial size=2>System.out.println(node.getNodeValue());</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>// Test the node.</FONT></DIV> <DIV><FONT face=Arial size=2>if (node.getNodeValue() == "and")</FONT></DIV> <DIV><FONT face=Arial size=2> System.out.println("it worked");</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>..</FONT></DIV> <DIV><FONT face=Arial size=2>============================================</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Now, I've confirmed that it's a text node before the snippet. The first println outputs "and". However, the "if" statement is false, so I never see "it worked". How is this possible?</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>This seems so trivial...what am I missing?</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Thanks in advance,</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Ryan</FONT></DIV></BODY></HTML>
|
|