You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2016/06/25 05:10:16 UTC

[jira] [Commented] (GROOVY-7874) XmlSlurper is dropping root node attributes

    [ https://issues.apache.org/jira/browse/GROOVY-7874?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15349062#comment-15349062 ] 

Paul King commented on GROOVY-7874:
-----------------------------------

No information is lost during parsing. Attributes are kept separate from namespaces. You can see this by the following code:
{code}
println schema.lookupNamespace('') // or 'xml' or 'xsd'
{code}
No WRT the {{serialize}} output, this is a little quirky I agree but is by design. Your XML doesn't make use of the root namespace, so that isn't output upon serialization.

> XmlSlurper is dropping root node attributes
> -------------------------------------------
>
>                 Key: GROOVY-7874
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7874
>             Project: Groovy
>          Issue Type: Bug
>          Components: XML Processing
>    Affects Versions: 2.4.3, 2.4.6, 2.4.7
>         Environment: MAC OS X, and Windows
>            Reporter: Mike Cargal
>            Priority: Minor
>
> When parsing an XML document with XmlSlurper, some attributes are being dropped.
> {code}
> import groovy.xml.*
> scSrc = '''<?xml version="1.0" encoding="UTF8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:cargal.net/myNS" xmlns="urn:cargal.net/myNS">
>     <xsd:element name="test" type="xsd:string"/>
> </xsd:schema>
> '''
> schema = new XmlSlurper().parseText(scSrc)
> println "schema.@attributeFormDefault=${schema.@attributeFormDefault}"
> println "schema.@xmlns=${schema.@xmlns}"
> println new XmlUtil().serialize(schema)
> {code}
> results:
> {noformat}
> schema.@attributeFormDefault=unqualified
> schema.@xmlns=
> <?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:cargal.net/myNS">
>   <xsd:element name="test" type="xsd:string"/>
> </xsd:schema>
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)