Hi all,
   I've been thinking to implement the fix for, jira issue XERCESJ-1674
(Namespace issue with xs:assert within xs:override), and have been stuck a
bit, and wish to discuss here the design of fix for this jira issue. Below
are the points, according to me about this jira issue.

1) What the issue is?

Lets assume that, we have following XSD and XML documents,

1674_1.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; xmlns:ns0="
http://test1/"; targetNamespace="http://test1/";
                    elementFormDefault="qualified"
attributeFormDefault="unqualified">

     <xs:override schemaLocation="1674_1_overridden.xsd">
        <xs:complexType name="Y2">
           <xs:sequence>
              <xs:element name="y" type="xs:integer"/>
           </xs:sequence>
           <xs:assert test="ns0:y mod 2 = 0"/>
        </xs:complexType>
     </xs:override>

     <xs:element name="X" type="ns0:Y2"/>

</xs:schema>

1674_1_overridden.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; xmlns:ns0_override="
http://over1/"; targetNamespace="http://test1/";
                    elementFormDefault="qualified"
attributeFormDefault="unqualified">

   <xs:complexType name="Y2">
      <xs:sequence>
         <xs:element name="y" type="xs:string"/>
      </xs:sequence>
   </xs:complexType>

</xs:schema>

1674_1.xml

<?xml version="1.0" encoding="UTF-8"?>
<X xmlns="http://test1/";>
  <y>1000</y>
</X>

The XML document, 1674_1.xml is validated with the XSD document, 1674_1.xsd
(which overrides, 1674_1_overridden.xsd).

The <xs:assert> 'test' XPath expression, within 1674_1.xsd refers to a
namespace prefix 'ns0' which is declared on the <xs:schema> element of
1674_1.xsd. With the current Xerces implementation, the <xs:assert>
evaluation fails with an error, 'Unknown prefix: ns0'. As mentioned by
person who raised this jira issue, and I agree as well, that the namespace
declaration (xmlns:ns0="http://test1/";) available on <xs:assert>'s ancestor
<xs:schema> element should be visible to the assertion (but that's
currently not the case).

With the current Xerces implementation, the namespace declarations on
<xs:schema> element of the XSD document, 1674_1_overridden.xsd are visible
to the <xs:assert> for the example mentioned above (which is a bug as well).

2) I looked at the code of XSDComplexTypeTraverser, which has an
object assertElement of type org.w3c.dom.Element (in method
traverseAsserts). When I find the owner DOM document instance of
assertElement, its the XSD document 1674_1_overridden.xsd (and not,
1674_1.xsd).
Had the owner DOM document instance of assertElement object been 1674_1.xsd
(which I wished), I was thinking to use DOM APIs to set the namespace
context right for the <xs:assert>.
Although, I don't know exactly, I guess the facts mentioned above in point
2) are because of a specific functional implementation of <xs:override>.

I would like to know, thoughts from someone who has knowledge of above
issues to help me write a fix for this jira issue. If anyone, wishes to
write fix for this jira issue or provide a patch, that's welcome as well.



-- 
Regards,
Mukul Gandhi

Reply via email to