Writing XML and Whitespace

Discussion in 'Java' started by Jason Cavett, Feb 23, 2007.

  1. Jason Cavett

    Jason Cavett Guest

    I've done some research and figured out how to fix my problem, but now
    I'm wondering why this whitespace problem happens.

    When I use the following code...

    OutputFormat format = new OutputFormat(document);
    format.setIndenting(false);
    XMLSerializer serializer = new XMLSerializer(new
    FileOutputStream(file), format);
    serializer.serialize(document);

    ....to write an XML document (org.w3c.dom.Document), the resulting
    output is fine. But, if set indenting to true (to make the XML look
    pretty), I get all these weird block characters in the resulting txt
    file. The file still opens up okay in my browser, but my application
    can't seem to handle it because the reader wants to treat those block
    characters as nodes.

    Any idea why this happens? Is there a way to fix this and still allow
    indenting in my document?


    Thanks
     
    Jason Cavett, Feb 23, 2007
    #1
    1. Advertising

  2. Jason Cavett

    Lew Guest

    Jason Cavett wrote:
    > output is fine. But, if set indenting to true (to make the XML look
    > pretty), I get all these weird block characters in the resulting txt
    > file. The file still opens up okay in my browser, but my application
    > can't seem to handle it because the reader wants to treat those block
    > characters as nodes.
    >
    > Any idea why this happens? Is there a way to fix this and still allow
    > indenting in my document?


    Is it literally every other character that appears to be a "block" in your
    "reader"?

    By the way, what browser? What reader? What application? How are you
    confirming in the .txt file what is in there?

    Does the viewer that you use to review the text file understand UTF-8 encoding?

    Writers and readers with different character encodings cause symptoms that
    some people might describe similarly, but without more precise information it
    is difficult to be certain if that is relevant.

    - Lew
     
    Lew, Feb 24, 2007
    #2
    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,368
    Uncle Pirate
    Jan 17, 2005
  2. kaens
    Replies:
    6
    Views:
    348
    Stefan Behnel
    May 23, 2007
  3. kaens
    Replies:
    0
    Views:
    392
    kaens
    May 23, 2007
  4. Replies:
    10
    Views:
    803
    Eric Brunel
    Dec 16, 2008
  5. MRAB
    Replies:
    3
    Views:
    409
Loading...

Share This Page