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?
Oliver Wong - 16 Oct 2006 17:33 GMT
>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?
See http://www.oracle.com/technology/pub/articles/wang-whitespace.html
- Oliver
Tom Forsmo - 17 Oct 2006 12:49 GMT
> 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