Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Preserve white space in text nodes

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT ibiblio.org>
  • To: XOM API for Processing XML with Java <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Preserve white space in text nodes
  • Date: Thu, 19 Jan 2012 06:21:39 -0500

On Wed, Jan 18, 2012 at 5:33 PM, Stevenson, Todd (GE Healthcare)
<Todd.T.Stevenson AT ge.com> wrote:
> This method:
>
> import nu.xom.Document;
> import nu.xom.Element;
> import nu.xom.Serializer;
>
>    void createXML() throws IOException {
>
>        Element root = new Element("Root");
>        Element child = new Element("Child");
>
>        child.appendChild("\n          first line   \n          second
> line\n");
>        root.appendChild(child);
>
>        Document doc = new Document(root);
>
>        Serializer serializer = new Serializer(System.out, "ISO-8859-1");
>        serializer.setIndent(4);
>        serializer.setMaxLength(100);

This is your problem. When you use setIndent and/or setMaxLength you
are telling the serializer to pretty print. I.e. you are telling it
that it should modify the white space so you have a certain line
length and indenting. If you want to preserve white space, don't do
that. Absent instructions to the contrary, XOM will preserve white
space in text nodes.

--
Elliotte Rusty Harold
elharo AT ibiblio.org




Archive powered by MHonArc 2.6.24.

Top of Page