Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-893

DOM level 3 : Cannot import 2 XSD within the same namespace

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Resolution: Fixed
    • 2.6.1
    • None
    • Other
    • None
    • Operating System: Windows NT/2K
      Platform: PC
    • 27055

    Description

      In a XSD schema such as:

      <xs:schema targetNamespace="ABC" xmlns:abc="ABC" xmlns:b="B" xmlns:c="B"
      xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
      attributeFormDefault="unqualified">
      <xs:import namespace="B" schemaLocation="B.xsd"/>
      <xs:import namespace="B" schemaLocation="C.xsd"/>
      <xs:element name="A">
      <xs:complexType>
      <xs:sequence>
      <xs:element name="B" type="b:BType"/>
      <xs:element name="C" type="c:CType"/>
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:schema>

      The second <import/> is ignored, along side the declaration for CType

      Using the following code:

      String strXml = "<A xmlns='ABC'><B>b</B><C>c</C></A>");
      javax.xml.parsers.DocumentBuilderFactory dbf=
      javax.xml.parsers.DocumentBuilderFactory.newInstance();
      dbf.setNamespaceAware(true);
      dbf.setAttribute("http://xml.org/sax/features/validation",Boolean.FALSE);
      dbf.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-
      dtd", Boolean.FALSE);
      javax.xml.parsers.DocumentBuilder parser = dbf.newDocumentBuilder();
      // Load XML without validating it
      Document dom = parser.parse(new org.xml.sax.InputSource(new java.io.StringReader
      (strXml)));

      // Now validate against arbitrary schema
      org.w3c.dom.DOMConfiguration config = Document.getDomConfig();
      config.setParameter("error-handler", myErrorHandler);
      config.setParameter("validate", Boolean.TRUE);
      config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
      config.setParameter("schema-location", "ABC A.xsd");
      Document.normalizeDocument();

      I get the following parsing error:
      error at (9, 46)! src-resolve: Cannot resolve the name 'c:CType' to a 'type
      definition' component.

      ======================================
      For completeness:

      B.XSD

      <xs:schema targetNamespace="B" xmlns:xs="http://www.w3.org/2001/XMLSchema"
      elementFormDefault="qualified" attributeFormDefault="unqualified">
      <xs:simpleType name="BType">
      <xs:restriction base="xs:string">
      <xs:pattern value="[bB]*"/>
      </xs:restriction>
      </xs:simpleType>
      </xs:schema>

      C.XSD

      <xs:schema targetNamespace="B" xmlns:xs="http://www.w3.org/2001/XMLSchema"
      elementFormDefault="qualified" attributeFormDefault="unqualified">
      <xs:simpleType name="CType">
      <xs:restriction base="xs:string">
      <xs:pattern value="[cC]*"/>
      </xs:restriction>
      </xs:simpleType>
      </xs:schema>

      ========================================

      Also, everything works perfectly when importing elements from different
      namespaces:

      A.XSD

      <xs:schema targetNamespace="ABC" xmlns:abc="ABC" xmlns:b="B" xmlns:c="C"
      xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
      attributeFormDefault="unqualified">
      <xs:import namespace="B" schemaLocation="B.xsd"/>
      <xs:import namespace="B" schemaLocation="C.xsd"/>

      [... as before]

      C.XSD

      <xs:schema targetNamespace="C"
      [... as before]

      Attachments

        1. ASF.LICENSE.NOT.GRANTED--A.xsd
          0.6 kB
          Franck Schmidlin
        2. ASF.LICENSE.NOT.GRANTED--B.xsd
          0.3 kB
          Franck Schmidlin
        3. ASF.LICENSE.NOT.GRANTED--C.xsd
          0.3 kB
          Franck Schmidlin

        Activity

          People

            Unassigned Unassigned
            franck.schmidlin@anite.com Franck Schmidlin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: