Java & XML

W

Will

I have an XML document that I am parsing with JAXP.
The XML document has a segment:

<heading class="heading 1" ... ... ...

If i parse this attribute and put the string value into a variable, say
named value. If i then System.out.println(value) i will see

heading 1

This is fine, but if i were to do the following:

if (value.equals("heading 1")) {
code
}

The code will not execute. Why is this, and how can i remedy the
problem?
 
D

Daniel Dyer

I have an XML document that I am parsing with JAXP.
The XML document has a segment:

<heading class="heading 1" ... ... ...

If i parse this attribute and put the string value into a variable, say
named value. If i then System.out.println(value) i will see

heading 1

This is fine, but if i were to do the following:

if (value.equals("heading 1")) {
code
}

The code will not execute. Why is this, and how can i remedy the
problem?

It's a different space character. You can use the \u00A0 escape sequence
to specify the non-breaking space in Java (or change your XML so that it
uses a regular space).

Dan.
 
W

Will

I am working with XML documents created by an external piece of
software so unfortunately cannot change the XML.

Is there a way i can "decode" the string so that I can compare parsed
strings with strings i code. (Ie value.equals("heading 1"))
 
D

David Wahler

Will said:
I am working with XML documents created by an external piece of
software so unfortunately cannot change the XML.

Is there a way i can "decode" the string so that I can compare parsed
strings with strings i code. (Ie value.equals("heading 1"))

Did you read the comment you just replied to?

value.equals("heading\u00A01")

-- David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top