XML and Line Breaks/Whitespace

Discussion in 'Java' started by JC, Oct 16, 2006.

  1. JC

    JC Guest

    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?
    JC, Oct 16, 2006
    #1
    1. Advertising

  2. JC

    Oliver Wong Guest

    "JC" <> wrote in message
    news:...
    >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
    Oliver Wong, Oct 16, 2006
    #2
    1. Advertising

  3. JC

    Tom Forsmo Guest

    JC wrote:
    > 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
    Tom Forsmo, Oct 17, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oli Filth
    Replies:
    9
    Views:
    3,323
    Uncle Pirate
    Jan 17, 2005
  2. Replies:
    10
    Views:
    738
    Eric Brunel
    Dec 16, 2008
  3. MRAB
    Replies:
    3
    Views:
    383
  4. bernadou

    Force multi line field value to output with line breaks?

    bernadou, Jan 22, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    354
    bernadou
    Jan 23, 2006
  5. Marek Stepanek
    Replies:
    12
    Views:
    410
    Peter J. Holzer
    Sep 2, 2006
Loading...

Share This Page