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

"Upwards" inheritance of properties with schema include

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 2.6.2
    • None
    • None
    • Windows XP
      J2sdk1.4.2_06

    Description

      I've observed this behaviour of XML Schemas: When an abstract complexType extends a concrete complexType, the latter is treated as abstract as well. This only occurs when the concrete type is defined in another file that is included into the schema.

      This is reproduced in the following schema files.
      Base.xsd:
      <?xml version="1.0" encoding="UTF-8"?>
      <xs:schema targetNamespace="http://w3c.org/test"
      xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://w3c.org/test">
      <xs:complexType name="Base" abstract="false"/>
      </xs:schema>

      test.xsd:
      <?xml version="1.0" encoding="UTF-8"?>
      <xs:schema targetNamespace="http://w3c.org/test"
      xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://w3c.org/test">
      <xs:include schemaLocation="Base.xsd"/>
      <xs:complexType name="Derived" abstract="true">
      <xs:complexContent>
      <xs:extension base="Base"/>
      </xs:complexContent>
      </xs:complexType>
      <xs:element name="base" type="Base"/>
      </xs:schema>

      The validation of the file test.xml below fails with cvc-type.2: The type definition cannot be abstract for element base.

      test.xml:
      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <base xmlns="http://w3c.org/test"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

      I'm using the follwing code to validate the schema.

      XercesTest.java:
      public class XercesTest {
      private static final ContentHandler contentHandler = new ContentHandler() {
      public void endDocument() {
      }

      public void startDocument() {
      }

      public void characters(char[] ch, int start, int length) {
      }

      public void ignorableWhitespace(char[] ch, int start, int length) {
      }

      public void endPrefixMapping(String prefix) {
      }

      public void skippedEntity(String name) {
      }

      public void setDocumentLocator(Locator locator) {
      }

      public void processingInstruction(String target, String data) {
      }

      public void startPrefixMapping(String prefix, String uri) {
      }

      public void endElement(String namespaceURI, String localName, String qName) {
      }

      public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
      }
      };

      private static final ErrorHandler errorHandler = new ErrorHandler() {
      public void error(SAXParseException exception) throws SAXException

      { throw exception; }

      public void fatalError(SAXParseException exception) throws SAXException { throw exception; }

      public void warning(SAXParseException exception)

      { exception.printStackTrace(); }

      };

      public static void main(String[] args) throws Throwable {
      try

      { XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); URL schemaUrl = XercesTest.class.getResource("/test.xsd"); parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", "http://w3c.org/test " + schemaUrl); parser.setFeature("http://xml.org/sax/features/validation", true); parser.setFeature("http://apache.org/xml/features/validation/schema", true); parser.setContentHandler(contentHandler); parser.setErrorHandler(errorHandler); parser.parse(new InputSource(XercesTest.class.getResourceAsStream("/test.xml"))); }

      catch (Exception e)

      { e.printStackTrace(); }

      }
      }

      Attachments

        Activity

          People

            mrglavas@ca.ibm.com Michael Glavassevich
            oihougaard Ole Hougaard
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: