You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Yitzhak Khabinsky <Yi...@Millicom.com> on 2018/08/08 15:11:18 UTC

Xerces-J 2.12.0 vs. Saxon: XSD 1.1 gYearMonth comparison is failing

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.khabinsky@millicom.com<ma...@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>


Re: Xerces-J 2.12.0 vs. Saxon: XSD 1.1 gYearMonth comparison is failing

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Yitzhak,
    I think, it would be ok if any bugs found for Eclipse / PsychoPath
XPath 2.0 processor in our 2.12.0 release, should be reported in Xerces
Jira. That would help us maintain the list of bugs in general. I hope we'll
find an appropriate way to fix these bugs in near future.

You could create the Xerces Jira issues, for the Eclipse / PsychoPath XPath
2.0 bugs you've found so far that we've discussed in recent threads.

On Wed, Aug 8, 2018 at 8:41 PM Yitzhak Khabinsky <
Yitzhak.Khabinsky@millicom.com> wrote:

> 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,
Mukul Gandhi

Re: Xerces-J 2.12.0 vs. Saxon: XSD 1.1 gYearMonth comparison is failing

Posted by Mukul Gandhi <mu...@apache.org>.
On Fri, Aug 10, 2018 at 9:58 PM, ykhabins <yi...@millicom.com>
wrote:

> It seems like a bug in the *Eclipse/PsychoPath XPath 2.0 engine* that
> Xerces is using.
>
> https://www.w3.org/TR/xpath-functions-31/#func-gYearMonth-equal
> 19.1 Casting from primitive types to primitive types The w3c spec.
> explicitly shows that xs:date shall convert into xs:gYearMonth
>
You've pointed to the spec, "XPath and XQuery Functions and Operators 3.1"
with the link above. XSD 1.1 uses XPath 2.0. Therefore the right link
should have been,
https://www.w3.org/TR/xquery-operators/#casting-from-primitive-to-primitive.
This section allows a cast from xs:date to xs:gYearMonth. Therefore you're
right.

Just to try identify the bug, I tested following <assert> XPath expressions
with Xerces XSD 1.1, and the results I got are also mentioned,

<xs:assert test="xs:gYearMonth('2018-07') eq xs:gYearMonth('2018-07')"/>

<xs:assert test="string(xs:gYearMonth(xs:date('2018-07-05'))) eq
'2018-07'"/>

<xs:assert test="xs:gYearMonth(xs:date('2018-07-05')) eq
xs:gYearMonth('2018-07')"/>

The first two of above <assert>'s gave a true result. The third one gives a
false result (this looks like a bug). We also need to revisit XPath 2.0
atomization in this area I think.

The XPath 2.0 processor that Xerces uses, is from Eclipse WTP Source
Editing project. Earlier we used to have commit rights on the Eclipse WTP
Source Editing project. But currently we don't have commit rights on that
project. Therefore as of now, we're not in position to fix any XPath 2.0
bugs identified after Xerces 2.12.0 release. I apologize, if you find this
current situation inconvenient.





-- 
Regards,
Mukul Gandhi

Re: Xerces-J 2.12.0 vs. Saxon: XSD 1.1 gYearMonth comparison is failing

Posted by ykhabins <yi...@millicom.com>.
It seems like a bug in the *Eclipse/PsychoPath XPath 2.0 engine* that Xerces
is using.
https://www.w3.org/TR/xpath-functions-31/#func-gYearMonth-equal
19.1 Casting from primitive types to primitive typesThe w3c spec. explicitly
shows that xs:date shall convert into xs:gYearMonth




--
Sent from: http://apache-xml-project.6118.n7.nabble.com/Xerces-J-Users-f4.html

Re: Xerces-J 2.12.0 vs. Saxon: XSD 1.1 gYearMonth comparison is failing

Posted by Mukul Gandhi <mu...@apache.org>.
>
> On Thu, Aug 9, 2018 at 7:24 PM, Yitzhak Khabinsky <
> Yitzhak.Khabinsky@millicom.com> wrote:
>
>> The idea is to use the *gYearMonth* data type so it will check
>> correctness of both year and month portions of it.
>>
>
The XPath expression in your <assert> makes use of the syntax,
xs:gYearMonth(xs:date(.)). This form of constructor for xs:gYearMonth which
takes xs:date as argument,
doesn't seem to be supported properly by our XPath 2.0 processor. I also
can't find anywhere in the XPath 2.0 & related specifications, where this
is allowed and the
semantics of it.




-- 
Regards,
Mukul Gandhi

Re: Xerces-J 2.12.0 vs. Saxon: XSD 1.1 gYearMonth comparison is failing

Posted by Mukul Gandhi <mu...@apache.org>.
On Thu, Aug 9, 2018 at 7:24 PM, Yitzhak Khabinsky <
Yitzhak.Khabinsky@millicom.com> wrote:

> The expression in the assert is working in Saxon with flying colors.
>
> The idea is to use the *gYearMonth* data type so it will check
> correctness of both year and month portions of it.
>

I think, the workaround XPath expressions I mentioned also solves your
problem. We also can't rule out the possibility that, Saxon could also have
a bug.
The XPath 2.0 processor available within Xerces, has passed all tests from
W3C XPath 2.0 test suite; therefore its trustworthy I believe.




-- 
Regards,
Mukul Gandhi

RE: Xerces-J 2.12.0 vs. Saxon: XSD 1.1 gYearMonth comparison is failing

Posted by Yitzhak Khabinsky <Yi...@Millicom.com>.
Hi Mukul,

The expression in the assert is working in Saxon with flying colors.
The idea is to use the gYearMonth data type so it will check correctness of both year and month portions of it.

The real limitation is that the XSD 1.1 standard prevents use of the inheritable attributes in the asserts which is the opposite from what CTAs allow.
So it forces the assert to work just once in one-to-many fashion, i.e. <root> where @DataFeed attribute resides vs. multiple <r> with the Date elements in this case.

Please see the screenshots below.
They show that there is nothing wrong with the XPath expression.

[cid:image001.png@01D42FC5.A0F39DD0]

[cid:image002.png@01D42FC5.A0F39DD0]

Regards,
Yitzhak Khabinsky

From: Mukul Gandhi [mailto:mukulg@apache.org]
Sent: Thursday, August 9, 2018 1:18 AM
To: Yitzhak Khabinsky <Yi...@Millicom.com>
Cc: j-users@xerces.apache.org
Subject: Re: Xerces-J 2.12.0 vs. Saxon: XSD 1.1 gYearMonth comparison is failing

Hi Yitzhak,

On Wed, Aug 8, 2018 at 8:41 PM, Yitzhak Khabinsky <Yi...@millicom.com>> wrote:
            <xs:assert test="empty(r/Date[xs:gYearMonth(xs:date(.)) ne ../../xs:gYearMonth(@DataFeed)])"

I can't exactly debug your above XPath expression quickly. I'm sure, someone from Xerces team or community will offer advise about above XPath expression asap, in relation to XSD 1.1 <assert>.

In the meantime, I can offer following XPath 2.0 expressions as workaround for your usecase, which seem to work with Xerces.

empty(r/Date[substring(string(.),0,8) ne string(../../@DataFeed)<mailto:../../@DataFeed)>])

or

every $d in r/Date satisfies substring(string($d),0,8) eq string(@DataFeed)





--
Regards,
Mukul Gandhi


This message (including any attachments) may contain confidential, proprietary, privileged and/or private information. The information is intended to be for the use of the individual or entity designated above. If you are not the intended recipient of this message or have received this transmission in error, please notify the sender immediately, and delete the message and any attachments. Any disclosure, reproduction, distribution or other use of this message or any attachments by an individual or entity other than the intended recipient is prohibited.

Este mensaje (incluido cualquiera de sus anexos) puede contener información confidencial, privilegiada, propietaria, y/o privada. La información está destinada para el uso del individuo o la entidad designada arriba. Si usted no es el destinatario de este mensaje o ha recibido este mensaje por error, por favor notifique a su remitente inmediatamente, y elimine el mensaje y cualquiera de sus anexos. Se prohíbe cualquier revelación, reproducción, distribución u otro uso de este mensaje o cualquiera de sus anexos que sea realizado por un individuo o una entidad diferente al destinatario.

Re: Xerces-J 2.12.0 vs. Saxon: XSD 1.1 gYearMonth comparison is failing

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Yitzhak,

On Wed, Aug 8, 2018 at 8:41 PM, Yitzhak Khabinsky <
Yitzhak.Khabinsky@millicom.com> wrote:

>             <xs:assert test="empty(r/Date[xs:gYearMonth(xs:date(.)) ne
> ../../xs:gYearMonth(@DataFeed)])"
>

I can't exactly debug your above XPath expression quickly. I'm sure,
someone from Xerces team or community will offer advise about above XPath
expression asap, in relation to XSD 1.1 <assert>.

In the meantime, I can offer following XPath 2.0 expressions as workaround
for your usecase, which seem to work with Xerces.

empty(r/Date[substring(string(.),0,8) ne string(../../@DataFeed)])

or

every $d in r/Date satisfies substring(string($d),0,8) eq string(@DataFeed)





-- 
Regards,
Mukul Gandhi