groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Cargal (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-7874) When serializing a document with xmlUtil, namespaces that are actually necessary, are being dropped as "unused"
Date Sat, 25 Jun 2016 20:40:37 GMT

     [ https://issues.apache.org/jira/browse/GROOVY-7874?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Mike Cargal updated GROOVY-7874:
--------------------------------
    Description: 
The following code segment demonstrates parsing a schema and then serializing with xmlUtil.
 xmlUtil, in it's attempt to discard necessary namespaces, is discarding namespaces that are
actually needed.

Save the original schema and the referenced schema in eclipse, and there will be no errors.
 Save the output schema (as MyRevSchema.xsd for example) and you'll have errors as a result
of the dropped namespaces.

{code}
import groovy.xml.*

scSrc = '''<?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" xmlns="urn:cargal.net/myNS"
    xmlns:myns="urn:cargal.net/myNS">
    <xsd:include schemaLocation="MyRefSchema.xsd" />
    <xsd:complexType name="myCT2">
        <xsd:complexContent>
            <xsd:extension base="myns:myCT">
                <xsd:sequence>
                    <xsd:element name="element1" />
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:element name="test" type="myns:myCT" />
    <xsd:element name="test2" substitutionGroup="subG" type="myCT2" />
</xsd:schema>
'''

schema = new XmlSlurper().parseText(scSrc)
println schema.lookupNamespace('')
println schema.lookupNamespace('myns')
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:include schemaLocation="MyRefSchema.xsd"/>
  <xsd:complexType name="myCT2">
    <xsd:complexContent>
      <xsd:extension base="myns:myCT">
        <xsd:sequence>
          <xsd:element name="element1"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:element name="test" type="myns:myCT"/>
  <xsd:element name="test2" substitutionGroup="subG" type="myCT2"/>
</xsd:schema>
{noformat}

For reference:  MyRefSchema.xsd
{noformat}
<?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" xmlns="urn:cargal.net/myNS"
	xmlns:myns="urn:cargal.net/myNS">
	<xsd:complexType name="myCT">
		<xsd:sequence>
			<xsd:element name="element1" />
		</xsd:sequence>
	</xsd:complexType>
	<xsd:element name="subG" type="myCT" />
</xsd:schema>
{noformat}

  was:
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}


        Summary: When serializing a document with xmlUtil, namespaces that are actually necessary,
are being dropped as "unused"  (was: XmlSlurper is dropping root node attributes)

I've revised the description to reflect the problem being in xmlUtil, and that it is too aggressive
in removing namespaces it believes to be unnecessary, with an example of how the  resulting
schema is no longer valid (while the input schema, without the dropped namespaces, was valid)

> When serializing a document with xmlUtil, namespaces that are actually necessary, are
being dropped as "unused"
> ---------------------------------------------------------------------------------------------------------------
>
>                 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
>
> The following code segment demonstrates parsing a schema and then serializing with xmlUtil.
 xmlUtil, in it's attempt to discard necessary namespaces, is discarding namespaces that are
actually needed.
> Save the original schema and the referenced schema in eclipse, and there will be no errors.
 Save the output schema (as MyRevSchema.xsd for example) and you'll have errors as a result
of the dropped namespaces.
> {code}
> import groovy.xml.*
> scSrc = '''<?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" xmlns="urn:cargal.net/myNS"
>     xmlns:myns="urn:cargal.net/myNS">
>     <xsd:include schemaLocation="MyRefSchema.xsd" />
>     <xsd:complexType name="myCT2">
>         <xsd:complexContent>
>             <xsd:extension base="myns:myCT">
>                 <xsd:sequence>
>                     <xsd:element name="element1" />
>                 </xsd:sequence>
>             </xsd:extension>
>         </xsd:complexContent>
>     </xsd:complexType>
>     <xsd:element name="test" type="myns:myCT" />
>     <xsd:element name="test2" substitutionGroup="subG" type="myCT2" />
> </xsd:schema>
> '''
> schema = new XmlSlurper().parseText(scSrc)
> println schema.lookupNamespace('')
> println schema.lookupNamespace('myns')
> 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:include schemaLocation="MyRefSchema.xsd"/>
>   <xsd:complexType name="myCT2">
>     <xsd:complexContent>
>       <xsd:extension base="myns:myCT">
>         <xsd:sequence>
>           <xsd:element name="element1"/>
>         </xsd:sequence>
>       </xsd:extension>
>     </xsd:complexContent>
>   </xsd:complexType>
>   <xsd:element name="test" type="myns:myCT"/>
>   <xsd:element name="test2" substitutionGroup="subG" type="myCT2"/>
> </xsd:schema>
> {noformat}
> For reference:  MyRefSchema.xsd
> {noformat}
> <?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" xmlns="urn:cargal.net/myNS"
> 	xmlns:myns="urn:cargal.net/myNS">
> 	<xsd:complexType name="myCT">
> 		<xsd:sequence>
> 			<xsd:element name="element1" />
> 		</xsd:sequence>
> 	</xsd:complexType>
> 	<xsd:element name="subG" type="myCT" />
> </xsd:schema>
> {noformat}



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

Mime
View raw message