Re: Re: Extra linefeeds with groovy.xml.XmlUtil.serialize

2023-04-06 Thread Jörg Prante


Hi Erick,

Groovy's XmlUtil is using javax.xml.transform.Transformer
OutputKeys.INDENT property.

Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");

In Java 9, the indentation behavior changed. Please note

https://bugs.openjdk.org/browse/JDK-8087303

and

https://bugs.openjdk.org/browse/JDK-8262285

Cheers, 

Jörg

Am Freitag, dem 31.03.2023 um 22:35 + schrieb Nelson, Erick:
> + normalize
>  
> I see no difference with or without normalize
>  
> Java 17 (and same results from 10,18,19)
> en032339@C02CJMZ8MD6M bin % ./java -version
> java version "17.0.6" 2023-01-17 LTS
> Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190)
> Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed
> mode, sharing)
>  
>  
> en032339@C02CJMZ8MD6M test1 % cat src/test.groovy
> import groovy.xml.*
>  
> String xml = $/
>  banana="yellow" apple="red"/>
> /$
>  
> def doc = new XmlParser().parseText(xml)
>  
> new File('test.xml').withWriter('UTF-8') { it <<
> XmlUtil.serialize(doc).normalize() }
> en032339@C02CJMZ8MD6M test1 % cat test.xml       
> 
>     
>   
>     
>   
>   
> 
> en032339@C02CJMZ8MD6M test1 % hexdump -C test.xml
>  3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 | version="1|
> 0010 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 |.0"
> encoding="UT|
> 0020 46 2d 38 22 3f 3e 3c 72 6f 6f 74 3e 0a 20 20 20 |F-
> 8"?>.  |
> 0030 20 0a 20 20 3c 65 72 69 63 6b 20 62 61 6e 61 6e | .   banan|
> 0040 61 3d 22 79 65 6c 6c 6f 77 22 20 61 70 70 6c 65 |a="yellow"
> apple|
> 0050 3d 22 72 65 64 22 2f 3e 0a 20 20 20 20 0a 20 20 |="red"/>. 
>   .  |
> 0060 3c 65 72 69 63 6b 20 63 72 79 70 74 6f 2d 62 61 | crypto-ba|
> 0070 6e 61 6e 61 3d 22 79 65 6c 6c 6f 77 22 20 61
> 70 |nana="yellow" ap|
> 0080 70 6c 65 3d 22 72 65 64 22 2f 3e 0a 20 20 0a
> 3c |ple="red"/>. .<|
> 0090 2f 72 6f 6f 74 3e 0a                             |/root>.|
> 0097
>  
>  
> Output using java 8
> en032339@C02CJMZ8MD6M bin % ./java -version   
> java version "1.8.0_251"
> Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
> Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
>  
>  
> en032339@C02CJMZ8MD6M test1 % cat test.xml       
> 
>   
>   
> 
> en032339@C02CJMZ8MD6M test1 % hexdump -C test.xml
>  3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 | version="1|
> 0010 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 |.0"
> encoding="UT|
> 0020 46 2d 38 22 3f 3e 3c 72 6f 6f 74 3e 0a 20 20 3c |F-
> 8"?>. <|
> 0030 65 72 69 63 6b 20 62 61 6e 61 6e 61 3d 22 79 65 |erick
> banana="ye|
> 0040 6c 6c 6f 77 22 20 61 70 70 6c 65 3d 22 72 65 64 |llow"
> apple="red|
> 0050 22 2f 3e 0a 20 20 3c 65 72 69 63 6b 20 63 72 79 |"/>. 
>  0060 70 74 6f 2d 62 61 6e 61 6e 61 3d 22 79 65 6c 6c |pto-
> banana="yell|
> 0070 6f 77 22 20 61 70 70 6c 65 3d 22 72 65 64 22 2f |ow"
> apple="red"/|
> 0080 3e 0a 3c 2f 72 6f 6f 74 3e 0a                   |>..|
> 008a
>  
>  
> Above code run from Eclipse. Maybe that matters?
>  
> XmlSlurper…. No see none of the above issues.
>  
>  
> From:Paul King 
> Date: Friday, March 31, 2023 at 11:27 AM
> To: users@groovy.apache.org 
> Subject: [EXT] Re: Extra linefeeds with groovy.xml.XmlUtil.serialize
> 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
>  wrote:
> >  
> >  
> > From:Nelson, Erick 
> > Date: Friday, March 31, 2023 at 7:53 AM
> > To: 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. 

Re: Re: Extra linefeeds with groovy.xml.XmlUtil.serialize

2023-03-31 Thread Nelson, Erick
+ normalize

I see no difference with or without normalize

Java 17 (and same results from 10,18,19)

en032339@C02CJMZ8MD6M bin % ./java -version

java version "17.0.6" 2023-01-17 LTS

Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190)

Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed mode, sharing)



en032339@C02CJMZ8MD6M test1 % cat src/test.groovy

import groovy.xml.*



String xml = $/



/$



def doc = new XmlParser().parseText(xml)



new File('test.xml').withWriter('UTF-8') { it << 
XmlUtil.serialize(doc).normalize() }

en032339@C02CJMZ8MD6M test1 % cat test.xml





  



  





en032339@C02CJMZ8MD6M test1 % hexdump -C test.xml

  3c 3f 78 6d 6c 20 76 65  72 73 69 6f 6e 3d 22 31  |.   |

0030  20 0a 20 20 3c 65 72 69  63 6b 20 62 61 6e 61 6e  | .  ..  |

0060  3c 65 72 69 63 6b 20 63  72 79 70 74 6f 2d 62 61  |.  .<|

0090  2f 72 6f 6f 74 3e 0a  |/root>.|

0097


Output using java 8

en032339@C02CJMZ8MD6M bin % ./java -version

java version "1.8.0_251"

Java(TM) SE Runtime Environment (build 1.8.0_251-b08)

Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)



en032339@C02CJMZ8MD6M test1 % cat test.xml



  

  



en032339@C02CJMZ8MD6M test1 % hexdump -C test.xml

  3c 3f 78 6d 6c 20 76 65  72 73 69 6f 6e 3d 22 31  |.  <|

0030  65 72 69 63 6b 20 62 61  6e 61 6e 61 3d 22 79 65  |erick banana="ye|

0040  6c 6c 6f 77 22 20 61 70  70 6c 65 3d 22 72 65 64  |llow" apple="red|

0050  22 2f 3e 0a 20 20 3c 65  72 69 63 6b 20 63 72 79  |"/>.  ..|

008a


Above code run from Eclipse. Maybe that matters?

XmlSlurper…. No see none of the above issues.


From: Paul King 
Date: Friday, March 31, 2023 at 11:27 AM
To: users@groovy.apache.org 
Subject: [EXT] Re: Extra linefeeds with groovy.xml.XmlUtil.serialize
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 
mailto:erick.nel...@hdsupply.com>> wrote:


From: Nelson, Erick 
mailto:erick.nel...@hdsupply.com>>
Date: Friday, March 31, 2023 at 7:53 AM
To: users@groovy.apache.org<mailto:users@groovy.apache.org> 
mailto: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 
mailto:erick.nel...@hdsupply.com>>
Date: Tuesday, March 21, 2023 at 10:25 AM
To: users@groovy.apache.org<mailto:users@groovy.apache.org> 
mailto: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 = $//$
def doc = new groovy.xml.XmlParser().parseText(xml)
println groovy.xml.XmlUtil.serialize(doc)
[tauser02@cfmips01ld0s work]$ groovy test.groovy







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 = $//$

def doc = new groovy.xml.XmlParser().parseText(xml)

println groovy.xml.XmlUtil.serialize(doc)

en032339@C02CJMZ8MD6M ~ % groovy test.groovy





  



  







Re: Extra linefeeds with groovy.xml.XmlUtil.serialize

2023-03-31 Thread Paul King
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 
wrote:

>
>
>
>
> *From: *Nelson, Erick 
> *Date: *Friday, March 31, 2023 at 7:53 AM
> *To: *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 
> *Date: *Tuesday, March 21, 2023 at 10:25 AM
> *To: *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 = $/ attr1="value1" attr2="value2"/> attr2="value4"/>/$
> def doc = new groovy.xml.XmlParser().parseText(xml)
> println groovy.xml.XmlUtil.serialize(doc)
> [tauser02@cfmips01ld0s work]$ groovy test.groovy
> 
> 
> 
> 
>
>
>
>
>
>
>
> *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 = $/ attr1="value1" attr2="value2"/> attr2="value4"/>/$
>
> def doc = new groovy.xml.XmlParser().parseText(xml)
>
> println groovy.xml.XmlUtil.serialize(doc)
>
> en032339@C02CJMZ8MD6M ~ % groovy test.groovy
>
> 
>
>
>
>   
>
>
>
>   
>
>
>
> 
>
>
>


Re: Extra linefeeds with groovy.xml.XmlUtil.serialize

2023-03-31 Thread Nelson, Erick


From: Nelson, Erick 
Date: Friday, March 31, 2023 at 7:53 AM
To: 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 
Date: Tuesday, March 21, 2023 at 10:25 AM
To: 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 = $//$
def doc = new groovy.xml.XmlParser().parseText(xml)
println groovy.xml.XmlUtil.serialize(doc)
[tauser02@cfmips01ld0s work]$ groovy test.groovy







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 = $//$

def doc = new groovy.xml.XmlParser().parseText(xml)

println groovy.xml.XmlUtil.serialize(doc)

en032339@C02CJMZ8MD6M ~ % groovy test.groovy





  



  







Re: Extra linefeeds with groovy.xml.XmlUtil.serialize

2023-03-31 Thread Nelson, Erick
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.
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 
Date: Tuesday, March 21, 2023 at 10:25 AM
To: 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 = $//$
def doc = new groovy.xml.XmlParser().parseText(xml)
println groovy.xml.XmlUtil.serialize(doc)
[tauser02@cfmips01ld0s work]$ groovy test.groovy







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 = $//$

def doc = new groovy.xml.XmlParser().parseText(xml)

println groovy.xml.XmlUtil.serialize(doc)

en032339@C02CJMZ8MD6M ~ % groovy test.groovy





  



  







Extra linefeeds with groovy.xml.XmlUtil.serialize

2023-03-21 Thread Nelson, Erick
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 = $//$
def doc = new groovy.xml.XmlParser().parseText(xml)
println groovy.xml.XmlUtil.serialize(doc)
[tauser02@cfmips01ld0s work]$ groovy test.groovy







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 = $//$

def doc = new groovy.xml.XmlParser().parseText(xml)

println groovy.xml.XmlUtil.serialize(doc)

en032339@C02CJMZ8MD6M ~ % groovy test.groovy