Re: XML Schema Validation Error Report

Herong Yang <[email protected]> Fri, 19 Jun 2020 12:07:07 +0000 (UTC)
Newsgroups gmane.text.xml.xerces-j.user
Message-ID <[email protected]>
------=_Part_529933_2123117929.1592568427667
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi=C2=A0Mukul,
Thank you for your=C2=A0response and suggestion. The current error report i=
s clear and useful. But I still think it will be nice if both 'A' and 'B' a=
re listed in the error report, since both of them are not expected to be th=
ere. =C2=A0
Herong
    On Friday, June 19, 2020, 2:47:09 PM GMT+8, Mukul Gandhi <mukulg@apache=
.org> wrote: =20
=20
 Hi=C2=A0Herong,
On Thu, Jun 18, 2020 at 12:29 PM Herong Yang <[email protected]> wrote:

By default, Xerces2 only reports only the first invalid sub-element and ski=
ps other subsequent invalid siblings. Is the any way to set Xerces2 to repo=
rt all invalid sub-elements?

I don't think that, what you're asking for is possible with Xerces-J.
Personally, I do find the error report you're getting with your XML and XSD=
 document samples, from Xerces-J to be useful.=C2=A0
Here is the sample XML:=C2=A0<?xml version=3D"1.0"?><root> <X/> <A/> <Y/> <=
B/></root>
Here is the XML Schema:=C2=A0<?xml version=3D"1.0"?><xs:schema xmlns:xs=3D"=
http://www.w3.org/2001/XMLSchema">=C2=A0 <xs:element name=3D"root"> <xs:com=
plexType> <xs:all> <xs:element name=3D"X" minOccurs=3D"0"/> <xs:element nam=
e=3D"Y" minOccurs=3D"0"/> </xs:all> </xs:complexType> </xs:element></xs:sch=
ema>
Here is the Xerces2 validation output:=C2=A0[Error] simple_4.xml:4:6: cvc-c=
omplex-type.2.4.a: Invalid content was found starting with element 'A'. One=
 of '{Y}' is expected.
I want to see both element 'A' and element 'B' being reported in the output=
.

For your requirements stated above, I could probably suggest the following =
XML Schema 1.1 document (which makes the intent of XML Schema logic more cl=
ear),
<?xml version=3D"1.0"?><xs:schema xmlns:xs=3D"http://www.w3.org/2001/XMLSch=
ema">
=C2=A0 =C2=A0<xs:element name=3D"root">=C2=A0 =C2=A0 =C2=A0 <xs:complexType=
>  <xs:sequence> =C2=A0 =C2=A0<xs:any processContents=3D"skip" minOccurs=3D=
"0" maxOccurs=3D"2"/>  </xs:sequence>  <xs:assert test=3D"if (count(*) =3D =
0) then true() else =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (count(*) =3D 1) then (*[1]/n=
ame() =3D ('X', 'Y')) else =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (count(*) =3D 2) then =
((*[1]/name() =3D 'X' and *[2]/name() =3D 'Y') =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 or =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (*[1]/name() =3D 'Y' and *[2]/name() =3D=
 'X')) else =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 false()"/>=C2=A0 =C2=A0 =C2=A0 </xs:comp=
lexType>=C2=A0 =C2=A0</xs:element>=C2=A0 =C2=A0</xs:schema>
=C2=A0
--=20
Regards,
Mukul Gandhi
 =20
------=_Part_529933_2123117929.1592568427667
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html><head></head><body><div class=3D"ydp576a7d61yahoo-style-wrap" style=
=3D"font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 1=
3px;"><div><div dir=3D"ltr" data-setdir=3D"false" style=3D"font-family: Hel=
vetica Neue, Helvetica, Arial, sans-serif; font-size: 13px;">Hi&nbsp;<span =
style=3D"color: rgb(38, 40, 42);">Mukul,</span></div><div dir=3D"ltr" data-=
setdir=3D"false" style=3D"font-family: Helvetica Neue, Helvetica, Arial, sa=
ns-serif; font-size: 13px;"><span style=3D"color: rgb(38, 40, 42);"><br></s=
pan></div><div dir=3D"ltr" data-setdir=3D"false"><font color=3D"#26282a">Th=
ank you for your&nbsp;<span>response and suggestion. The current error repo=
rt is clear and useful. But I still think it will be nice if both 'A' and '=
B' are listed in the error report, since both of them are not expected to b=
e there. </span></font>&nbsp;</div><div dir=3D"ltr" data-setdir=3D"false"><=
font color=3D"#26282a"><span><br></span></font></div><div class=3D"ydp576a7=
d61signature" style=3D"font-family: Helvetica Neue, Helvetica, Arial, sans-=
serif; font-size: 13px;">Herong</div></div><div style=3D"font-family: Helve=
tica Neue, Helvetica, Arial, sans-serif; font-size: 13px;"><br></div>
       =20
        </div><div id=3D"ydp2dfdf514yahoo_quoted_2878827882" class=3D"ydp2d=
fdf514yahoo_quoted">
            <div style=3D"font-family:'Helvetica Neue', Helvetica, Arial, s=
ans-serif;font-size:13px;color:#26282a;">
               =20
                <div>
                    On Friday, June 19, 2020, 2:47:09 PM GMT+8, Mukul Gandh=
i &lt;[email protected]&gt; wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div id=3D"ydp2dfdf514yiv5604728757"><div><div dir=3D"=
ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div>Hi&nbsp;Herong,</div><br clear=
=3D"none"><div class=3D"ydp2dfdf514yiv5604728757gmail_quote"><div class=3D"=
ydp2dfdf514yiv5604728757gmail_attr" dir=3D"ltr">On Thu, Jun 18, 2020 at 12:=
29 PM Herong Yang &lt;<a shape=3D"rect" href=3D"mailto:[email protected]=
m" rel=3D"nofollow" target=3D"_blank">[email protected]</a>&gt; wrote:<=
/div><div class=3D"ydp2dfdf514yiv5604728757gmail_attr" dir=3D"ltr"><br clea=
r=3D"none"></div><blockquote class=3D"ydp2dfdf514yiv5604728757gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pa=
dding-left:1ex;"><div style=3D"font-family:Helvetica, Arial, sans-serif;fon=
t-size:13px;"><div dir=3D"ltr">By default, Xerces2 only reports only the fi=
rst invalid sub-element and skips other subsequent invalid siblings. Is the=
 any way to set Xerces2 to report all invalid sub-elements?</div></div></bl=
ockquote><div><br clear=3D"none"></div><div>I don't think that, what you're=
 asking for is possible with Xerces-J.</div><div><br clear=3D"none"></div><=
div>Personally, I do find the error report you're getting with your XML and=
 XSD document samples, from Xerces-J to be useful.</div><div>&nbsp;</div><b=
lockquote class=3D"ydp2dfdf514yiv5604728757gmail_quote" style=3D"margin:0px=
 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;"><d=
iv style=3D"font-family:Helvetica, Arial, sans-serif;font-size:13px;"><div =
dir=3D"ltr">Here is the sample XML:&nbsp;</div><div dir=3D"ltr"><div><div>&=
lt;?xml version=3D"1.0"?&gt;</div><div>&lt;root&gt;</div><div><span style=
=3D"white-space:pre-wrap;">=09</span>&lt;X/&gt;</div><div><span style=3D"wh=
ite-space:pre-wrap;">=09</span>&lt;A/&gt;</div><div><span style=3D"white-sp=
ace:pre-wrap;">=09</span>&lt;Y/&gt;</div><div><span style=3D"white-space:pr=
e-wrap;">=09</span>&lt;B/&gt;</div><div>&lt;/root&gt;</div><div dir=3D"ltr"=
><br clear=3D"none"></div></div><div dir=3D"ltr">Here is the XML Schema:&nb=
sp;</div><div dir=3D"ltr"><div><div>&lt;?xml version=3D"1.0"?&gt;</div><div=
>&lt;xs:schema xmlns:xs=3D"<a shape=3D"rect" href=3D"http://www.w3.org/2001=
/XMLSchema" rel=3D"nofollow" target=3D"_blank">http://www.w3.org/2001/XMLSc=
hema</a>"&gt;&nbsp;</div><div><span style=3D"white-space:pre-wrap;">=09</sp=
an>&lt;xs:element name=3D"root"&gt;</div><div><span style=3D"white-space:pr=
e-wrap;">=09=09</span>&lt;xs:complexType&gt;</div><div><span style=3D"white=
-space:pre-wrap;">=09=09=09</span>&lt;xs:all&gt;</div><div><span style=3D"w=
hite-space:pre-wrap;">=09=09=09=09</span>&lt;xs:element name=3D"X" minOccur=
s=3D"0"/&gt;</div><div><span style=3D"white-space:pre-wrap;">=09=09=09=09</=
span>&lt;xs:element name=3D"Y" minOccurs=3D"0"/&gt;</div><div><span style=
=3D"white-space:pre-wrap;">=09=09=09</span>&lt;/xs:all&gt;</div><div><span =
style=3D"white-space:pre-wrap;">=09=09</span>&lt;/xs:complexType&gt;</div><=
div><span style=3D"white-space:pre-wrap;">=09</span>&lt;/xs:element&gt;</di=
v><div dir=3D"ltr">&lt;/xs:schema&gt;</div></div></div></div><div dir=3D"lt=
r"><br clear=3D"none"></div><div dir=3D"ltr">Here is the Xerces2 validation=
 output:&nbsp;</div><div dir=3D"ltr"><span></span><div>[Error] simple_4.xml=
:4:6: cvc-complex-type.2.4.a: Invalid content was found starting with eleme=
nt 'A'. One of '{Y}' is expected.</div><div><br clear=3D"none"></div><div d=
ir=3D"ltr">I want to see both element 'A' and element 'B' being reported in=
 the output.</div></div></div></blockquote><div><br clear=3D"none"></div><d=
iv>For your requirements stated above, I could probably suggest the followi=
ng XML Schema 1.1 document (which makes the intent of XML Schema logic more=
 clear),</div><div><br clear=3D"none"></div><div><div>&lt;?xml version=3D"1=
.0"?&gt;</div><div>&lt;xs:schema xmlns:xs=3D"<a shape=3D"rect" href=3D"http=
://www.w3.org/2001/XMLSchema" rel=3D"nofollow" target=3D"_blank">http://www=
.w3.org/2001/XMLSchema</a>"&gt;</div><div><br clear=3D"none"></div><div>&nb=
sp; &nbsp;&lt;xs:element name=3D"root"&gt;</div><div>&nbsp; &nbsp; &nbsp; &=
lt;xs:complexType&gt;</div><div><span style=3D"white-space: pre-wrap;">=09<=
/span> &lt;xs:sequence&gt;</div><div><span style=3D"white-space: pre-wrap;"=
>=09</span>&nbsp; &nbsp;&lt;xs:any processContents=3D"skip" minOccurs=3D"0"=
 maxOccurs=3D"2"/&gt;</div><div><span style=3D"white-space: pre-wrap;">=09<=
/span> &lt;/xs:sequence&gt;</div><div><span style=3D"white-space: pre-wrap;=
">=09</span> &lt;xs:assert test=3D"if (count(*) =3D 0) then true() else</di=
v><div><span style=3D"white-space: pre-wrap;">=09</span>&nbsp; &nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp; if (count(*) =3D 1) then (*[1]/name() =3D ('X', 'Y')) else</div><div><s=
pan style=3D"white-space: pre-wrap;">=09</span>&nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (c=
ount(*) =3D 2) then ((*[1]/name() =3D 'X' and *[2]/name() =3D 'Y')</div><di=
v><span style=3D"white-space: pre-wrap;">=09</span>&nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; or</div><div><span style=3D"whit=
e-space: pre-wrap;">=09</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; (*[1]/name() =3D 'Y' and *[2]/name() =3D 'X')) else</div><di=
v><span style=3D"white-space: pre-wrap;">=09</span>&nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f=
alse()"/&gt;</div><div class=3D"ydp2dfdf514yiv5604728757yqt9081838169" id=
=3D"ydp2dfdf514yiv5604728757yqtfd35654"><div>&nbsp; &nbsp; &nbsp; &lt;/xs:c=
omplexType&gt;</div><div>&nbsp; &nbsp;&lt;/xs:element&gt;</div><div>&nbsp; =
&nbsp;</div><div>&lt;/xs:schema&gt;</div></div></div><div><br clear=3D"none=
"></div><div>&nbsp;</div></div><div><br clear=3D"none"></div>-- <br clear=
=3D"none"><div class=3D"ydp2dfdf514yiv5604728757gmail_signature" dir=3D"ltr=
"><div dir=3D"ltr"><div>Regards,<br clear=3D"none">Mukul Gandhi<div class=
=3D"ydp2dfdf514yiv5604728757yqt9081838169" id=3D"ydp2dfdf514yiv5604728757yq=
tfd52677"><br clear=3D"none"></div></div></div></div></div></div></div></di=
v></div></div>
            </div>
        </div></body></html>
------=_Part_529933_2123117929.1592568427667--