Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] [SPAM(hdr)] - Using Serializer with Indenting (without alteringAttribute values)

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Jens Kripl <jens.kripl AT gmx.de>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] [SPAM(hdr)] - Using Serializer with Indenting (without alteringAttribute values)
  • Date: Mon, 26 Sep 2011 20:46:26 +0200

Hi all,

sorry for getting back quite late:

> However if you tell XOM to change the white space by indenting, then
> yes, it will change the white space. If you don't want XOM to change
> the white space, don't use indenting.

Understood. But when people end up using DOM (or javax.xml.Transformer
like me) for indenting, maybe something with the behavior is not
perfect.

So you asked for a test, here it is (hope that's the right for to
submit it):

(just add this test to "nu.xom.tests.SerializerTest")

public void testAttributeWithIndenting() throws IOException {

root.addAttribute(new Attribute("Name", "Hello Name"));
root.appendChild(new Element("sameline"));
ByteArrayOutputStream out = new ByteArrayOutputStream();
Serializer serializer = new Serializer(out, "UTF-8");
serializer.setIndent(4);
serializer.write(doc);
String result = out.toString("UTF-8");
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
+ "<root Name=\"Hello Name\">\r\n"
+ " <sameline/>\r\n"
+ "</root>\r\n", result);
}

Regards,
Jens

Am 16.09.2011 12:01:37 CEST
schrieb xom-interest-request AT lists.ibiblio.org:

> Send XOM-interest mailing list submissions to
> xom-interest AT lists.ibiblio.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.ibiblio.org/mailman/listinfo/xom-interest
> or, via email, send a message with subject or body 'help' to
> xom-interest-request AT lists.ibiblio.org
>
> You can reach the person managing the list at
> xom-interest-owner AT lists.ibiblio.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of XOM-interest digest..."
>
>
> Today's Topics:
>
> 1. Re: [SPAM(hdr)] - Using Serializer with Indenting
> (without alteringAttribute values) (Peter Taylor)
> 2. Re: [SPAM(hdr)] - Using Serializer with Indenting (without
> alteringAttribute values) (Elliotte Rusty Harold)
> 3. Re: [SPAM(hdr)] - Using Serializer with Indenting
> (without alteringAttribute values) (Leif Stainsby)
> 4. Re: [SPAM(hdr)] - Using Serializer with Indenting (without
> alteringAttribute values) (Elliotte Rusty Harold)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 15 Sep 2011 17:25:16 +0100
> From: "Peter Taylor" <peter.taylor AT greenhat.com>
> Subject: Re: [XOM-interest] [SPAM(hdr)] - Using Serializer with
> Indenting (without alteringAttribute values)
> To: "XOM API for Processing XML with Java"
> <xom-interest AT lists.ibiblio.org>
> Message-ID:
> <1C8E52697A489F429275597D15DB3DE704E0AA34 AT ghc-winsvr1.greenhat.local>
> Content-Type: text/plain; charset="us-ascii"
>
> Certiainly there never use to be. I ended up transforming the XOM to
> DOM.
>
> Then it's easy to indent and you'd expect:
>
> http://www.chipkillmar.net/2009/03/25/pretty-print-xml-from-a-dom/
>
> -----Original Message-----
> From: xom-interest-bounces AT lists.ibiblio.org
> [mailto:xom-interest-bounces AT lists.ibiblio.org] On Behalf Of Jens
> Kripl Sent: 15 August 2011 20:57
> To: xom-interest AT lists.ibiblio.org
> Subject: [SPAM(hdr)] - [XOM-interest] Using Serializer with Indenting
> (without alteringAttribute values)
>
> Hi,
>
> I'm using the Serializer to pretty print my XOM constructed XML.
> I've read the javadoc and some comments on the list that it may change
> whitespace, but this is really a problem for me:
>
> Before : <foo name="Abc CdeF" />
> After : <foo name="Abc CdeF" />
> Expected: <foo name="Abc CdeF" />
>
> Is there any way to change this behaviour? The value of the attribute
> should not be changed, but elements should be indented.
>
>
> Regards,
> Jens
> _______________________________________________
> XOM-interest mailing list
> XOM-interest AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/xom-interest
>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 15 Sep 2011 18:40:42 -0400
> From: Elliotte Rusty Harold <elharo AT ibiblio.org>
> Subject: Re: [XOM-interest] [SPAM(hdr)] - Using Serializer with
> Indenting (without alteringAttribute values)
> To: XOM API for Processing XML with Java
> <xom-interest AT lists.ibiblio.org>
> Message-ID:
> <CAGhczrpd5CganUdtXNYJMSzFRkpuiWio12iP-yFbWSRL-1_MbQ AT mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> On Thu, Sep 15, 2011 at 12:25 PM, Peter Taylor
> <peter.taylor AT greenhat.com> wrote:
> > Certiainly there never use to be. I ended up transforming the XOM to
> > DOM.
> >
> > Then it's easy to indent and you'd expect:
> >
> > http://www.chipkillmar.net/2009/03/25/pretty-print-xml-from-a-dom/
> >
> > -----Original Message-----
> > From: xom-interest-bounces AT lists.ibiblio.org
> > [mailto:xom-interest-bounces AT lists.ibiblio.org] On Behalf Of Jens
> > Kripl Sent: 15 August 2011 20:57
> > To: xom-interest AT lists.ibiblio.org
> > Subject: [SPAM(hdr)] - [XOM-interest] Using Serializer with
> > Indenting (without alteringAttribute values)
> >
> > Hi,
> >
> > I'm using the Serializer to pretty print my XOM constructed XML.
> > I've read the javadoc and some comments on the list that it may
> > change whitespace, but this is really a problem for me:
> >
> > Before : <foo name="Abc CdeF" />
> > After : <foo name="Abc CdeF" />
> > Expected: <foo name="Abc CdeF" />
> >
> > Is there any way to change this behaviour? The value of the
> > attribute should not be changed, but elements should be indented.
> >
>
> there are several things that could be happening here. Do you have a
> test case?
>
> However if you tell XOM to change the white space by indenting, then
> yes, it will change the white space. If you don't want XOM to change
> the white space, don't use indenting.
>
>




Archive powered by MHonArc 2.6.24.

Top of Page