Kapil Verma created XERCESJ-1664:
------------------------------------

             Summary: Validation of a DOM created on fly against schema 
validator fails to recognize attributes
                 Key: XERCESJ-1664
                 URL: https://issues.apache.org/jira/browse/XERCESJ-1664
             Project: Xerces2-J
          Issue Type: Bug
          Components: JAXP (javax.xml.validation)
    Affects Versions: 2.11.0
         Environment: Win7, java 1.8
            Reporter: Kapil Verma


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 expose 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 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(i);
                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.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to