If you add ".normalize()", does that make any difference? I am trying to
determine is there are CR chars in the output. Perhaps piping to od or some
octal/hex dump program.

There are also various parser options/features that might be different on
different platforms.

Does XmlSlurper exhibit the same behavior?

Can you try trimWhitespace and keepIgnorableWhitespace on XmlParser?

There are also setFeature and setProperty methods on XmlParser. I don't
think they will help in your case but they have helped for other tricky XML
scenarios.

Cheers, Paul.


On Sat, Apr 1, 2023 at 1:24 AM Nelson, Erick <erick.nel...@hdsupply.com>
wrote:

>
>
>
>
> *From: *Nelson, Erick <erick.nel...@hdsupply.com>
> *Date: *Friday, March 31, 2023 at 7:53 AM
> *To: *users@groovy.apache.org <users@groovy.apache.org>
> *Subject: *Re: Extra linefeeds with groovy.xml.XmlUtil.serialize
>
> This appears to be a Java problem, not a Groovy problem,  and possibly an
> OpenJDK issue.
>
> I’ve only been able to test this further on my Mac laptop as I cannot
> install different versions of Java*. Redhat ON LINUX*
>
> Java 8 works as expected
>
> I’ve tried Java 10, 11, 17, 18 and 19 and all appear to exhibit this
> behavior
>
>
>
> *From: *Nelson, Erick <erick.nel...@hdsupply.com>
> *Date: *Tuesday, March 21, 2023 at 10:25 AM
> *To: *users@groovy.apache.org <users@groovy.apache.org>
> *Subject: *Extra linefeeds with groovy.xml.XmlUtil.serialize
>
> I get extra line feeds on my mac when running identical code. Does
> anybody know why this would be?
>
>
>
> *On Linux… (expected output)*
>
>
>
> [tauser02@cfmips01ld0s work]$ groovy -v
> Groovy Version: 4.0.10 JVM: 1.8.0_362 Vendor: Red Hat, Inc. OS: Linux
> [tauser02@cfmips01ld0s work]$ cat test.groovy
> String xml = $/<?xml version="1.0" encoding="UTF-8"?><root><elem1
> attr1="value1" attr2="value2"/><elem2 attr1="value4"
> attr2="value4"/></root>/$
> def doc = new groovy.xml.XmlParser().parseText(xml)
> println groovy.xml.XmlUtil.serialize(doc)
> [tauser02@cfmips01ld0s work]$ groovy test.groovy
> <?xml version="1.0" encoding="UTF-8"?><root>
> <elem1 attr1="value1" attr2="value2"/>
> <elem2 attr1="value4" attr2="value4"/>
> </root>
>
>
>
>
>
>
>
> *On my MAC…(note extra line feeds output)*
>
>
>
> en032339@C02CJMZ8MD6M ~ % groovy -v
>
> Groovy Version: 4.0.10 JVM: 18.0.2.1 Vendor: Eclipse Adoptium OS: Mac OS X
>
> en032339@C02CJMZ8MD6M ~ % cat test.groovy
>
> String xml = $/<?xml version="1.0" encoding="UTF-8"?><root><elem1
> attr1="value1" attr2="value2"/><elem2 attr1="value4"
> attr2="value4"/></root>/$
>
> def doc = new groovy.xml.XmlParser().parseText(xml)
>
> println groovy.xml.XmlUtil.serialize(doc)
>
> en032339@C02CJMZ8MD6M ~ % groovy test.groovy
>
> <?xml version="1.0" encoding="UTF-8"?><root>
>
>
>
>   <elem1 attr1="value1" attr2="value2"/>
>
>
>
>   <elem2 attr1="value4" attr2="value4"/>
>
>
>
> </root>
>
>
>

Reply via email to