Re: Re: Possible Bug: Xerces 2.12.1 for XML Validation with XSD 1.1 Schema under Java - Plain Text
Mukul Gandhi <[email protected]> Sun, 23 Aug 2020 12:16:34 +0530
| Newsgroups | gmane.text.xml.xerces-j.user |
|---|---|
| Message-ID | <CABuuzNO8rF9icd2ZB-CJL1SRngG8KVnMM_tbCcHyLEgE-xdGhA@mail.gmail.com> |
--000000000000a9f6e205ad85d59f Content-Type: text/plain; charset="UTF-8" On Sat, Aug 22, 2020 at 10:27 PM JOHN Morris <[email protected]> wrote: > I note your reference to using jaxp.SourceValidator/ I'm not sure whether > you are claiming that, if you use that, you don't see any of the problems > that I have highlighted(?) > I didn't mean that. Its just that, my personal preference to do XSD validation with Xerces-J, for your examples, is to use Xerces-J sample jaxp.SourceValidator. > I find that seemingly good XML constructs cause validation error WHEN > THOSE XML CONSTRUCTS OCCUR AT CERTAIN PROBLEMATIC LINE NUMBERS e.g. line > 44, in my test1.xml file). However, those exact same constructs DO NOT > trigger errors if they appear at different XML line numbers. For example, > if I insert an XML comment line before one of these constructs,formerly > appearing at a problematic line number, so that it now appears at the > subsequent line number, it no longer triggers an error!!! That was what the > second test file was supposed to illustrate. > I don't experience these things. For me, both of your XML documents (test1.xml and test2.xml) when validated by your XSD document (test.xsd), produces same sort of errors. My validation attempts using Xerces-J, produces about 9 validation errors for both of the XML documents that are validated. I'm not sure, what is different at your side. > As for using xs:pattern, my imagination was not rich enough to know how to > achieve the same effect as I was trying to get with 'matches' but now with > xs:pattern. Have you been able to visualise how to do that? > Let's say you wish to have <xs:assert test="if (./text()[matches(.,'^(install\.xml)$')]) then @file else true()"/> written using xs:pattern instead of XPath 2.0 'matches' function. Following should be the steps to do this, 1) Create an XSD simple type definition <xs:simpleType name="StringType1"> <xs:restriction base="xs:string"> <xs:pattern value="regex_expr"/> <xs:restriction> </xs:simpleType> 2) Write the xs:assert as following <xs:assert test="if (./text() castable as StringType1) then @file else true()"/> (the above suggested XSD fragments, are not tested from my side) Another minor point. I had to add the following XML prolog to your XML documents that are to be validated, <?xml version="1.0" encoding="ISO-8859-1"?> (your XML documents contain few characters, that cannot be represented with the default encoding UTF-8). -- Regards, Mukul Gandhi --000000000000a9f6e205ad85d59f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div di= r=3D"ltr"><div dir=3D"ltr">On Sat, Aug 22, 2020 at 10:27 PM JOHN Morris <= ;[email protected]> wrote:<br></div><div class=3D"gmail_qu= ote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bo= rder-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u> =20 <div><p>I note your reference to using jaxp.SourceValidator/ I'm not su= re whether you are claiming that, if you use that, you don't see any of= the problems that I have highlighted(?)<br></p></div></blockquote><div>I d= idn't mean that. Its just that, my personal preference to do XSD valida= tion with Xerces-J, for your=C2=A0examples, is to use Xerces-J sample jaxp.= SourceValidator.</div><blockquote class=3D"gmail_quote" style=3D"margin:0px= 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><di= v><p>I find that seemingly good XML constructs cause validation error WHEN = THOSE XML CONSTRUCTS OCCUR AT CERTAIN PROBLEMATIC LINE NUMBERS e.g. line 44= , in my test1.xml file). However, those exact same constructs DO NOT trigge= r errors if they appear at different XML line numbers. For example, if I in= sert an XML comment line before one of these constructs,formerly appearing = at a problematic line number, so that it now appears at the subsequent line= number, it no longer triggers an error!!! That was what the second test fi= le was supposed to illustrate.<br></p></div></blockquote><div>I don't e= xperience these things. For me, both of your XML documents (test1.xml and t= est2.xml) when validated by your XSD document (test.xsd), produces same sor= t of errors. My validation attempts using Xerces-J, produces about 9 valida= tion errors for both of the XML documents that are validated. I'm not s= ure, what is different at your side.</div><blockquote class=3D"gmail_quote"= style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p= adding-left:1ex"><div><p>As for using xs:pattern, my imagination was not ri= ch enough to know how to achieve the same effect as I was trying to get wit= h 'matches' but now with xs:pattern. Have you been able to visualis= e how to do that?</p></div></blockquote><div>Let's say you wish to have= =C2=A0<xs:assert test=3D"if (./text()[matches(.,'^(install\.xml= )$')]) then @file else true()"/> written using xs:pattern inste= ad of XPath 2.0 'matches' function.</div><div><br></div><div>Follow= ing should be the steps to do this,</div><div><br></div><div>1) Create an X= SD simple type definition<br></div><div><br></div><div><xs:simpleType na= me=3D"StringType1"></div><div>=C2=A0 =C2=A0 <xs:restriction= base=3D"xs:string"></div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0<xs:pattern value=3D"regex_expr"/></div><div>=C2=A0 =C2= =A0 <xs:restriction></div><div></xs:simpleType></div><div><br><= /div><div>2) Write the xs:assert as following</div><div><br></div><div><= xs:assert test=3D"if (./text() castable as StringType1) then @file els= e true()"/><br></div><div><br></div><div>(the above suggested XSD f= ragments, are not tested from my side)</div><div><br></div><div>Another min= or point. I had to add the following XML prolog to your XML documents that = are to be validated,</div><div><?xml version=3D"1.0" encoding= =3D"ISO-8859-1"?><br></div><div><br></div><div>(your XML docum= ents contain few characters, that cannot be represented with the default en= coding UTF-8).</div><div><br></div><div>=C2=A0</div></div><div><br></div>--= <br><div dir=3D"ltr" class=3D"gmail_signature"><div dir=3D"ltr"><div>Regar= ds,<br>Mukul Gandhi<br></div></div></div></div></div></div></div></div> --000000000000a9f6e205ad85d59f--