From krueger at lesspain.de Sun Sep 29 07:42:54 2013 From: krueger at lesspain.de (=?UTF-8?Q?Robert_Kr=C3=BCger?=) Date: Sun, 29 Sep 2013 16:42:54 +0200 Subject: [jdom-interest] Formatting differences after migrating to JDOM2 Message-ID: Hi, I just migrated my code to from JDOM to JDOM2 and noticed some of our unit tests failed. The reason is different formatting. I used Format.getPrettyFormat().setTextMode(PRESERVE) for the formatting and with jdom this produced output like the following MP4 646448 2002002 0 1340887741000 VIDEO H.264 ... after replacing the imports by jdom2 I got MP4 646448 2002002 0 1340887741000 VIDEO H.264 ... This looks rather broken as it does not preserve the original data at all with all those added newlines. Removing the setTextMode(PRESERVE) restored the format to what is shown above but the reason I added setTextMode(PRESERVE) was that without it, whitespace was trimmed and I do not want that for elements with text content. Is this a bug? How can I achieve what I want, i.e. have a "pretty", i.e. indented format and have text-only elements preserve whitespace? Thanks in advance, Robert From garydgregory at gmail.com Sun Sep 29 08:11:10 2013 From: garydgregory at gmail.com (Gary Gregory) Date: Sun, 29 Sep 2013 11:11:10 -0400 Subject: [jdom-interest] Formatting differences after migrating to JDOM2 In-Reply-To: References: Message-ID: <4431590574511882573@unknownmsgid> Ty Gary On Sep 29, 2013, at 10:52, "Robert Kr?ger" wrote: > Hi, > > I just migrated my code to from JDOM to JDOM2 and noticed some of our > unit tests failed. The reason is different formatting. I used > Format.getPrettyFormat().setTextMode(PRESERVE) for the formatting and > with jdom this produced output like the following > > > MP4 > 646448 > 2002002 > 0 > 1340887741000 > > VIDEO > H.264 > ... > > after replacing the imports by jdom2 I got > > > > MP4 > > 646448 > > 2002002 > > 0 > > 1340887741000 > > > VIDEO > > H.264 > ... > > This looks rather broken as it does not preserve the original data at > all with all those added newlines. Removing the setTextMode(PRESERVE) > restored the format to what is shown above but the reason I added > setTextMode(PRESERVE) was that without it, whitespace was trimmed and > I do not want that for elements with text content. > > Is this a bug? How can I achieve what I want, i.e. have a "pretty", > i.e. indented format and have text-only elements preserve whitespace? > > Thanks in advance, > > Robert > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com From garydgregory at gmail.com Sun Sep 29 08:12:18 2013 From: garydgregory at gmail.com (Gary Gregory) Date: Sun, 29 Sep 2013 11:12:18 -0400 Subject: [jdom-interest] Formatting differences after migrating to JDOM2 In-Reply-To: References: Message-ID: <3887513264684273411@unknownmsgid> It also looks like no pretty formatting I've ever seen. Having a closing and opening tag on the same line is confusing. Gary On Sep 29, 2013, at 10:52, "Robert Kr?ger" wrote: > Hi, > > I just migrated my code to from JDOM to JDOM2 and noticed some of our > unit tests failed. The reason is different formatting. I used > Format.getPrettyFormat().setTextMode(PRESERVE) for the formatting and > with jdom this produced output like the following > > > MP4 > 646448 > 2002002 > 0 > 1340887741000 > > VIDEO > H.264 > ... > > after replacing the imports by jdom2 I got > > > > MP4 > > 646448 > > 2002002 > > 0 > > 1340887741000 > > > VIDEO > > H.264 > ... > > This looks rather broken as it does not preserve the original data at > all with all those added newlines. Removing the setTextMode(PRESERVE) > restored the format to what is shown above but the reason I added > setTextMode(PRESERVE) was that without it, whitespace was trimmed and > I do not want that for elements with text content. > > Is this a bug? How can I achieve what I want, i.e. have a "pretty", > i.e. indented format and have text-only elements preserve whitespace? > > Thanks in advance, > > Robert > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com From jdom at tuis.net Sun Sep 29 08:26:17 2013 From: jdom at tuis.net (Rolf) Date: Sun, 29 Sep 2013 11:26:17 -0400 Subject: [jdom-interest] Formatting differences after migrating to JDOM2 In-Reply-To: References: Message-ID: <52484699.6040002@tuis.net> Hi Robert. This is surprising indeed, and I agree it should not be different from JDOM 1.x Can you get me a copy of the input file and the relevant parts of Java code? You don't need to CC the whole list it is large... Thanks Rolf On 29/09/2013 10:42 AM, Robert Kr?ger wrote: > Hi, > > I just migrated my code to from JDOM to JDOM2 and noticed some of our > unit tests failed. The reason is different formatting. I used > Format.getPrettyFormat().setTextMode(PRESERVE) for the formatting and > with jdom this produced output like the following > > > MP4 > 646448 > 2002002 > 0 > 1340887741000 > > VIDEO > H.264 > ... > > after replacing the imports by jdom2 I got > > > > MP4 > > 646448 > > 2002002 > > 0 > > 1340887741000 > > > VIDEO > > H.264 > ... > > This looks rather broken as it does not preserve the original data at > all with all those added newlines. Removing the setTextMode(PRESERVE) > restored the format to what is shown above but the reason I added > setTextMode(PRESERVE) was that without it, whitespace was trimmed and > I do not want that for elements with text content. > > Is this a bug? How can I achieve what I want, i.e. have a "pretty", > i.e. indented format and have text-only elements preserve whitespace? > > Thanks in advance, > > Robert > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com > From krueger at lesspain.de Mon Sep 30 06:43:44 2013 From: krueger at lesspain.de (=?UTF-8?Q?Robert_Kr=C3=BCger?=) Date: Mon, 30 Sep 2013 15:43:44 +0200 Subject: [jdom-interest] Fwd: Formatting differences after migrating to JDOM2 In-Reply-To: References: <52484699.6040002@tuis.net> Message-ID: forgot to reply to the list ---------- Forwarded message ---------- From: Robert Kr?ger Date: Mon, Sep 30, 2013 at 3:42 PM Subject: Re: [jdom-interest] Formatting differences after migrating to JDOM2 To: Rolf This reproduces the behaviour: import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; public class JDOMOutput { public static void main(String argv[]) throws Exception{ Document document = new Document(); Element root = new Element("root"); document.addContent(root); Element sub1 = new Element("sub1"); root.addContent(sub1); sub1.addContent(new Element("sub2").setText("Some text")); sub1.addContent(new Element("sub2").setText(" text with left and right whitespace ")); new XMLOutputter(Format.getPrettyFormat().setTextMode(Format.TextMode.PRESERVE)).output(document, System.out); } } Try with and without the setTextMode(Format.TextMode.PRESERVE). None of them does what I need. On Sun, Sep 29, 2013 at 7:10 PM, Robert Kr?ger wrote: > Hi, > > it is part of a large application. I will try to build a simple test > program that demonstrates the effect. > > Cheers, > > Robert > > On Sun, Sep 29, 2013 at 5:26 PM, Rolf wrote: >> Hi Robert. >> >> This is surprising indeed, and I agree it should not be different from JDOM >> 1.x >> >> Can you get me a copy of the input file and the relevant parts of Java code? >> You don't need to CC the whole list it is large... >> >> Thanks >> >> Rolf >> >> >> On 29/09/2013 10:42 AM, Robert Kr?ger wrote: >>> >>> Hi, >>> >>> I just migrated my code to from JDOM to JDOM2 and noticed some of our >>> unit tests failed. The reason is different formatting. I used >>> Format.getPrettyFormat().setTextMode(PRESERVE) for the formatting and >>> with jdom this produced output like the following >>> >>> >>> MP4 >>> 646448 >>> 2002002 >>> 0 >>> 1340887741000 >>> >>> VIDEO >>> H.264 >>> ... >>> >>> after replacing the imports by jdom2 I got >>> >>> >>> >>> MP4 >>> >>> 646448 >>> >>> 2002002 >>> >>> 0 >>> >>> 1340887741000 >>> >>> >>> VIDEO >>> >>> H.264 >>> ... >>> >>> This looks rather broken as it does not preserve the original data at >>> all with all those added newlines. Removing the setTextMode(PRESERVE) >>> restored the format to what is shown above but the reason I added >>> setTextMode(PRESERVE) was that without it, whitespace was trimmed and >>> I do not want that for elements with text content. >>> >>> Is this a bug? How can I achieve what I want, i.e. have a "pretty", >>> i.e. indented format and have text-only elements preserve whitespace? >>> >>> Thanks in advance, >>> >>> Robert >>> _______________________________________________ >>> To control your jdom-interest membership: >>> http://www.jdom.org/mailman/options/jdom-interest/youraddr at yourhost.com >>> >>