Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7874

When serializing a document with xmlUtil, namespaces that are actually necessary, are being dropped as "unused"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.4.3, 2.4.6, 2.4.7
    • None
    • XML Processing
    • None
    • MAC OS X, and Windows

    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.

      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)
      

      results:

      urn:cargal.net/myNS
      urn:cargal.net/myNS
      <?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>
      

      For reference: MyRefSchema.xsd

      <?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>
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            mcargal Mike Cargal
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: