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

Validation of a DOM created on fly against schema validator fails to recognize attributes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.11.0
    • None
    • Win7, java 1.8
    • Important

    Description

      Trying to validate a DOM model which was created programmatically. Getting cvc error for id attribute on a node:

      cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'context'

      It works fine if the model is serialized and parsed into Xerces. On debugging it was found that when parsing the document, Xerces uses its own factory method to create the attributes:

      CoreDocumentImpl.createAttributeNS(String namespaceURI, String qualifiedName, String localpart)

      and creates an instance of AttrNSImpl.

      Since this method is not exposed via org.w3c.dom.Document API, external applications can't use it to create the instances of AttrNSImpl. The available API

      Document .createAttributeNS(String namespaceURI, String qualifiedName)

      calls a different constructor of AttrNSImpl which throws Exceptions if the namespace is null or empty.

      Because of that the, in cases where namespace is not known, external applications are forced to use Document.createAttribute(String name) which creates instances of AttrImpl.

      Now the problem with AttrImpl is that it returns null for all questions except getNodeName(). The validator doesn't like that. In DOMValidatorHelper.fillQName(QName toFill, Node node) the QName object is initialized using this AttrImpl object. Since everything except the node.getNodeName() returns null, the toFill object has only rawname populated.

      All this has consequence in XmlSchemaValidator.processAttributes() at line 2982:

      // it's not xmlns, and not xsi, then we need to find a decl for it
      ....
      ....
      oneUse = (XSAttributeUseImpl) attrUses.item;
      if (oneUse.fAttrDecl.fName == fTempQName.localpart
      && oneUse.fAttrDecl.fTargetNamespace == fTempQName.uri)

      { currUse = oneUse; break; }

      The check for oneUse.fAttrDecl.fName == fTempQName.localpart fails, because the localpart in fTempQName was not populated by the DOMValidatorHelper.processAttributes(). This results in error report at line 2998.

      Attachments

        Activity

          People

            Unassigned Unassigned
            kapildverma Kapil Verma
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: