Yeah, I had thought about that, but I had similar equiv. tests in my code
that worked.  The only difference is that they were pulling values from
element names and attributes, NOT element values.

In short, I should be using .equals() for all string comparisons.
Regardless, Xerces still should have returned that original element string
value equiv. as true and not added white space or whatever, no?

Now that I look at this problem, I realize that I've come across it before.
Ugh...I love Java, but this...ugh.

Thanks guys.

----- Original Message ----- 
From: "Kevin Klinemeier" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, October 20, 2003 6:59 PM
Subject: Re: Node.getNodeValue() problem


> Yep, stupid Java problem.
>
> You need to use .equals("and") to compare the strings.  the "=="
> operator tests for reference equality.  You have two String objects in
> memory, which have different references, so the "==" test fails.
> However, if you tell them to compare themselves, they'll figure out
> they mean the same thing.
>
> You can use internalize() on both to get the One True String for the
> system, but you really don't want to bother with that here.
>
> -Kevin
> --- Michael Ryan Bannon <[EMAIL PROTECTED]> wrote:
> > 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
>
>
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search
> http://shopping.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to