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: Christophe Marchand <christophe.marchand AT axyus.com>
  • To: XOM API for Processing XML with Java <xom-interest AT lists.ibiblio.org>
  • Cc: "Stevenson, Todd \(GE Healthcare\)" <Todd.T.Stevenson AT ge.com>
  • Subject: Re: [XOM-interest] Preserve white space in text nodes
  • Date: Thu, 19 Jan 2012 08:35:57 +0100

This works correctly for me.

Best regards,
Christophe

Le 18/01/2012 23:33, Stevenson, Todd (GE Healthcare) a écrit :
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.addAttribute(new Attribute("xml:space", XMLConstants.XML_NS_URI, "preserve"));
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);
serializer.write(doc);
}

Generates this output:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Root>
<Child> first line second line</Child>
</Root>


Note that it discards the extra white space and newline characters. I
want to be able to preserve this whitespace to the output XML document.

Thanks

-----Original Message-----
From: xom-interest-bounces AT lists.ibiblio.org
[mailto:xom-interest-bounces AT lists.ibiblio.org] On Behalf Of Elliotte Rusty
Harold
Sent: Wednesday, January 18, 2012 1:57 PM
To: XOM API for Processing XML with Java
Subject: Re: [XOM-interest] Preserve white space in text nodes

On Wed, Jan 18, 2012 at 2:06 PM, Stevenson, Todd (GE
Healthcare)<Todd.T.Stevenson AT ge.com> wrote:
I can't figure out how to preserve whitespace in a text node.

I use the serializer to write my output and it strips the spaces and newline
characters.

Is there a configuration option to make this work correctly?
Do you have code that demonstrates what's happening?


--
Elliotte Rusty Harold
elharo AT ibiblio.org
_______________________________________________
XOM-interest mailing list
XOM-interest AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/xom-interest
_______________________________________________
XOM-interest mailing list
XOM-interest AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/xom-interest






Archive powered by MHonArc 2.6.24.

Top of Page