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

Xerces 2 does not support JAXP 1.2 validation properties

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Resolution: Cannot Reproduce
    • 2.3.0
    • None
    • None
    • Operating System: Windows NT/2K
      Platform: PC
    • 17029

    Description

      The JAXP specification 1.2 specifies(in part) the following mechanism to
      request schema validation:
      --------------------------------------
      The setProperty method in SAXParser must support the property strings
      defined below to indicate the schema language and the source of the schema file
      (s) to the parser:
      http://java.sun.com/xml/jaxp/properties/schemaLanguage
      This property defines the schema language to be used for validation.
      The value of this property must be the URI of the schema language
      specification. To be compliant with this version of the specification, the
      implementation must support the W3C XML schema specification at this URI:
      http://www.w3.org/2001/XMLSchema.
      http://java.sun.com/xml/jaxp/properties/schemaSource
      The XML Schema Recommendation explicitly states that the inclusion of
      schemaLocation / noNamespaceSchemaLocation attributes in an instance document
      is only a hint; it does not mandate that these attributes must be used to
      locate schemas.

      The schemaSource property lets the user set the schema(s) to validate
      against. If the target namespace of a schema specified using this property
      matches the target namespace of a schema occuring in schemaLocation attribute,
      the schema specified by the user using this property will be used and the
      instance document's schemaLocation attribute will be effectively ignored.
      However if the target namespace of any schema specified using this property
      doesn't match the target namespace of a schema occuring in the instance
      document, then the hint specified in the instance document will be used for
      validation. The acceptable value for this property must be one of the following:
      •String that points to the URI of the schema
      •InputStream with the contents of the schema
      •SAX InputSource
      •File
      •an array of Objects with the contents being one of the types
      defined above.
      An array of Objects can be used only when the schema language has the
      ability to assemble a schema at runtime. When an array of Objects is passed it
      is illegal to have two schemas that share the same namespace.
      If no target namespace is defined, then only one schema can be
      referenced by the property and it must work exactly the way
      xsi:noNamespaceSchemaLocation does.

      When setValidating is set to true and a schema language is set, then
      the parser must validate against that schema language only. For example if an
      application sets the schemaLanguage property to XML Schemas then the parser
      must try to validate against the XML schema only, even if the document has a
      DOCTYPE declaration that refers to a DTD.
      [.....]
      The same property strings as described above for the SAXParser must be
      supported by
      DocumentBuilderFactory.setAttribute method.
      When setValidating is set to true and a schema language is set then the
      parser must validate against that schema language only. For example if an
      application sets the schema language property to XML Schemas the parser must
      try to validate against the XML schema only, even if the document has a DOCTYPE
      declaration that refers to a DTD.
      --------------------------------------
      When the following code fragment, an analog to the example in the
      specification, is called, the indicated error is thrown:
      ------
      xmlFactory = DocumentBuilderFactory.newInstance();
      xmlFactory.setExpandEntityReferences(true);
      xmlFactory.setNamespaceAware(true);
      xmlFactory.setValidating(true);
      xmlFactory.setAttribute
      ("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
      "http://www.w3.org/2001/XMLSchema");
      xmlFactory.setIgnoringElementContentWhitespace(true);

      DocumentBuilder xmlBuilder = xmlFactory.newDocumentBuilder();
      xmlDocument = xmlBuilder.parse(xmlStream);
      ------
      Error: URI=null Line=2: Document is invalid: no grammar found.
      Error: URI=null Line=2: Document root element "XXXXX", must match DOCTYPE
      root "null".

      Apparently, setting the schema validation per the JAXP specification does not
      properly activate schema validation in the Xerces parser, and the parser
      continues to attempt DTD validation. I am aware that there is a Xerces-
      specific attribute to enable schema, but our projects have a requirement to
      avoid product-specific calls when a standard API is available, and hence are
      limited to staying with Xerces 1.4.4 (which handles schema validation without
      product-specific attributes) until this issue is resolved in Xerces 2.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            joseph.sinclair@motorola.com Joseph Sinclair
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment