[jdom-interest] Single space in element content

Jan Moravec/SYD/CEtv JanMoravec at austar.com.au
Thu Jun 13 01:41:36 PDT 2002

Hi Jason,

I wrote a simple example that demonstrates the problem. When I serialize
the doc using a default XMLOutputter it works just fine, however, when I
want to pretty print it with newlines the entire content of el is gone.

Thanks for any hints.

Jan Moravec

import org.jdom.*;

public class JDOMTest
  public static void main(String[] args) throws Exception
    Element root = new Element("root");
    Element el = new Element("element_with_whitespace");
    el.addContent("  ");

    //XMLOutputter out = new XMLOutputter();  // works OK
    //XMLOutputter out = new XMLOutputter(" ", false, "UTF-8"); // works OK
    XMLOutputter out = new XMLOutputter(" ", true, "UTF-8"); // makes el an
empty element (why?)

    // out.setTrimAllWhite(false); // none of these has any efect
    // out.setTextTrim(false);
    // out.setTextNormalize(false);

    out.output(new Document(root), System.out);

Jason Hunter <jhunter at acm.org> on 08/06/2002 04:19:34 am

To:    Jan Moravec/SYD/CEtv <JanMoravec at austar.com.au>
cc:    jdom-interest at jdom.org

Subject:    Re: [jdom-interest] Single space in element content

> I tried both
> input.addContent( new Element("value").addContent(new Text(" ")) )
> and
> input.addContent( new Element("value").setText(" ") )
> but with the same result.

You don't really say what the "result" is.  There's many ways to view a
document.  Most likely if the space is disappearing it's because of how
you output it or how you read it in later.  What happens when you output
using a brand new untweaked XMLOutputter to System.out?


This message has been scanned for viruses by AUSTAR Communication's
antivirus and content checking applications.

Austar Communications

This email and any files transmitted with it, are confidential and is intended solely for the use of the individual or entity to whom they are addressed.
If you have received this email in error, please notify the system manager.

This footnote also confirms that this email message has been scanned by AUSTAR Communications content  and virus scanning applications
for the presence of computer viruses.

More information about the jdom-interest mailing list