Hello,

I have a requirement to validate that:
Each gYearMonth(Date) value shall not fall outside of a particular year-month 
range.
The test case XML/XSD is below.

XML:
<?xml version="1.0" encoding="UTF-8"?>
<root DataFeed="2018-07" xmlns="http://www.millicom.com"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://www.millicom.com Test3.xsd">
    <r>
        <Date>2018-07-31</Date>
    </r>
    <r>
        <Date>2018-07-25</Date>
    </r>
</root>

XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
elementFormDefault="qualified" version="4.4" 
targetNamespace="http://www.millicom.com"; xmlns="http://www.millicom.com"; 
xpathDefaultNamespace="##targetNamespace" xmlns:saxon="http://saxon.sf.net/";>
    <xs:element name="root">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="1" maxOccurs="unbounded" ref="r"/>
            </xs:sequence>
            <xs:attribute name="DataFeed" use="required" type="xs:gYearMonth"/>

            <xs:assert test="empty(r/Date[xs:gYearMonth(xs:date(.)) ne 
../../xs:gYearMonth(@DataFeed)])" saxon:message="Rule #0: Each Year-Month(Date) 
value shall be equal to the DataFeed attribute value" 
xpathDefaultNamespace="##targetNamespace">
                <xs:annotation>
                    <xs:documentation>Rule #0</xs:documentation>
                    <xs:documentation>Each Year-Month(Date) value shall be 
equal to the DataFeed attribute value</xs:documentation>
                </xs:annotation>
            </xs:assert>
        </xs:complexType>
    </xs:element>

    <xs:element name="r">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Date" type="xs:date"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Saxon correctly evaluates that the XML is valid.

XercesJ emits the following error:
[Error] Test3.xml:11:8: cvc-assertion: Assertion evaluation 
('empty(r/Date[xs:gYearMonth(xs:date(.)) ne ../../xs:gYearMonth(@DataFeed)])') 
for element 'root' on schema type '#AnonType_root' did not succeed.


Regards,
Yitzhak Khabinsky
Technical Services Lead
Millicom International Services LLC
396 Alhambra Circle, Suite 1100
Coral Gables, FL  33134
Skype4B: +1 (305) 445-4172
Tel: (954) 684-8673
yitzhak.khabin...@millicom.com<mailto:.khabin...@millicom.com>
www.millicom.com<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.millicom.com%2F&data=02%7C01%7CMalcolm.Stewart%40microsoft.com%7C9338023699c2494d08be08d4ad12ce55%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636323743686702678&sdata=DxQ9dfL259rpdVZ9seOAcR6bvgxRobyIerOgvTgPc90%3D&reserved=0>

Reply via email to