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 &lt=
;[email protected]&gt; 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&#39;m not su=
re whether you are claiming that, if you use that, you don&#39;t see any of=
 the problems that I have highlighted(?)<br></p></div></blockquote><div>I d=
idn&#39;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&#39;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&#39;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 &#39;matches&#39; but now with xs:pattern. Have you been able to visualis=
e how to do that?</p></div></blockquote><div>Let&#39;s say you wish to have=
=C2=A0&lt;xs:assert test=3D&quot;if (./text()[matches(.,&#39;^(install\.xml=
)$&#39;)]) then @file else true()&quot;/&gt; written using xs:pattern inste=
ad of XPath 2.0 &#39;matches&#39; 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>&lt;xs:simpleType na=
me=3D&quot;StringType1&quot;&gt;</div><div>=C2=A0 =C2=A0 &lt;xs:restriction=
 base=3D&quot;xs:string&quot;&gt;</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0&lt;xs:pattern value=3D&quot;regex_expr&quot;/&gt;</div><div>=C2=A0 =C2=
=A0 &lt;xs:restriction&gt;</div><div>&lt;/xs:simpleType&gt;</div><div><br><=
/div><div>2) Write the xs:assert as following</div><div><br></div><div>&lt;=
xs:assert test=3D&quot;if (./text() castable as StringType1) then @file els=
e true()&quot;/&gt;<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>&lt;?xml version=3D&quot;1.0&quot; encoding=
=3D&quot;ISO-8859-1&quot;?&gt;<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--