XML and Line Breaks/Whitespace

J

JC

I am parsing an XML file that has line breaks. When I use the method
"getChildNodes" on a Node (which returns a NodeList of the children of
that node), I am receiving the line breaks and spaces as children.

What is the best way to remove/ignore these line breaks? Can I do it
up front, or do I have to do it after I get the children nodes?
 
T

Tom Forsmo

JC said:
I am parsing an XML file that has line breaks. When I use the method
"getChildNodes" on a Node (which returns a NodeList of the children of
that node), I am receiving the line breaks and spaces as children.

What is the best way to remove/ignore these line breaks? Can I do it
up front, or do I have to do it after I get the children nodes?

Are you saying the parser returns content with line breaks/spaces after
what would be the end element/attribute or is the problem just generally
that the content of an element or attribute has line breaks?

Its not supposed be any line breaks after an element or attribute after
parsing, if there is there is a fault in the parser. But if there are in
the content its a matter independent of xml and can be fixed with any
standard string manipulation tools. Have a look at the StringUtil in
Apaches Commons or perhaps java regexp.

tom
 

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
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top