Re: XML Schema Validation Error Report
Mukul Gandhi <[email protected]> Fri, 19 Jun 2020 12:16:49 +0530
| Newsgroups | gmane.text.xml.xerces-j.user |
|---|---|
| Message-ID | <CABuuzNNC1oMz3Zr9A5xnPjdTSLCcgvho-zHJY4hwjiJ0MfP-og@mail.gmail.com> |
--000000000000f6121a05a86a42d8 Content-Type: text/plain; charset="UTF-8" Hi Herong, 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 > skips other subsequent invalid siblings. Is the any way to set Xerces2 to > report 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. > Here is the sample XML: > <?xml version="1.0"?> > <root> > <X/> > <A/> > <Y/> > <B/> > </root> > > Here is the XML Schema: > <?xml version="1.0"?> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:element name="root"> > <xs:complexType> > <xs:all> > <xs:element name="X" minOccurs="0"/> > <xs:element name="Y" minOccurs="0"/> > </xs:all> > </xs:complexType> > </xs:element> > </xs:schema> > > Here is the Xerces2 validation output: > [Error] simple_4.xml:4:6: cvc-complex-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 clear), <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:any processContents="skip" minOccurs="0" maxOccurs="2"/> </xs:sequence> <xs:assert test="if (count(*) = 0) then true() else if (count(*) = 1) then (*[1]/name() = ('X', 'Y')) else if (count(*) = 2) then ((*[1]/name() = 'X' and *[2]/name() = 'Y') or (*[1]/name() = 'Y' and *[2]/name() = 'X')) else false()"/> </xs:complexType> </xs:element> </xs:schema> -- Regards, Mukul Gandhi --000000000000f6121a05a86a42d8 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>Hi=C2=A0Herong,</di= v><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On T= hu, Jun 18, 2020 at 12:29 PM Herong Yang <<a href=3D"mailto:herong_yang@= yahoo.com">[email protected]</a>> wrote:</div><div dir=3D"ltr" class= =3D"gmail_attr"><br></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"= ><div style=3D"font-family:"Helvetica Neue",Helvetica,Arial,sans-= serif;font-size:13px"><div dir=3D"ltr">By default, Xerces2 only reports onl= y the first invalid sub-element and skips other subsequent invalid siblings= . Is the any way to set Xerces2 to report all invalid sub-elements?</div></= div></blockquote><div><br></div><div>I don't think that, what you'r= e asking for is possible with Xerces-J.</div><div><br></div><div>Personally= , I do find the error report you're getting with your XML and XSD docum= ent samples, from Xerces-J to be useful.</div><div>=C2=A0</div><blockquote = class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px sol= id rgb(204,204,204);padding-left:1ex"><div style=3D"font-family:"Helve= tica Neue",Helvetica,Arial,sans-serif;font-size:13px"><div dir=3D"ltr"= >Here is the sample XML:=C2=A0</div><div dir=3D"ltr"><div><div><?xml ver= sion=3D"1.0"?></div><div><root></div><div><span style=3D= "white-space:pre-wrap"> </span><X/></div><div><span style=3D"white-sp= ace:pre-wrap"> </span><A/></div><div><span style=3D"white-space:pre-w= rap"> </span><Y/></div><div><span style=3D"white-space:pre-wrap"> </s= pan><B/></div><div></root></div><div dir=3D"ltr"><br></div></di= v><div dir=3D"ltr">Here is the XML Schema:=C2=A0</div><div dir=3D"ltr"><div= ><div><?xml version=3D"1.0"?></div><div><xs:schema xmlns= :xs=3D"<a href=3D"http://www.w3.org/2001/XMLSchema" target=3D"_blank">= http://www.w3.org/2001/XMLSchema</a>">=C2=A0</div><div><span style= =3D"white-space:pre-wrap"> </span><xs:element name=3D"root">= ;</div><div><span style=3D"white-space:pre-wrap"> </span><xs:complexTyp= e></div><div><span style=3D"white-space:pre-wrap"> </span><xs:all&g= t;</div><div><span style=3D"white-space:pre-wrap"> </span><xs:element= name=3D"X" minOccurs=3D"0"/></div><div><span style= =3D"white-space:pre-wrap"> </span><xs:element name=3D"Y" mi= nOccurs=3D"0"/></div><div><span style=3D"white-space:pre-wrap"= > </span></xs:all></div><div><span style=3D"white-space:pre-wrap"> = </span></xs:complexType></div><div><span style=3D"white-space:pre-wr= ap"> </span></xs:element></div><div dir=3D"ltr"></xs:schema></d= iv></div></div></div><div dir=3D"ltr"><br></div><div dir=3D"ltr">Here is th= e Xerces2 validation output:=C2=A0</div><div dir=3D"ltr"><span><div>[Error]= simple_4.xml:4:6: cvc-complex-type.2.4.a: Invalid content was found starti= ng with element 'A'. One of '{Y}' is expected.</div><div><b= r></div><div dir=3D"ltr">I want to see both element 'A' and element= 'B' being reported in the output.</div></span></div></div></blockq= uote><div><br></div><div>For your requirements stated above, I could probab= ly suggest the following XML Schema 1.1 document (which makes the intent of= XML Schema logic more clear),</div><div><br></div><div><div><?xml versi= on=3D"1.0"?></div><div><xs:schema xmlns:xs=3D"<a href= =3D"http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>&= quot;></div><div><br></div><div>=C2=A0 =C2=A0<xs:element name=3D"= ;root"></div><div>=C2=A0 =C2=A0 =C2=A0 <xs:complexType></div>= <div><span style=3D"white-space:pre"> </span> <xs:sequence></div><div= ><span style=3D"white-space:pre"> </span>=C2=A0 =C2=A0<xs:any processCon= tents=3D"skip" minOccurs=3D"0" maxOccurs=3D"2"= ;/></div><div><span style=3D"white-space:pre"> </span> </xs:sequence&= gt;</div><div><span style=3D"white-space:pre"> </span> <xs:assert test= =3D"if (count(*) =3D 0) then true() else</div><div><span style=3D"whit= e-space:pre"> </span>=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= ]/name() =3D ('X', 'Y')) else</div><div><span style=3D"whit= e-space:pre"> </span>=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')</div><div><span = style=3D"white-space:pre"> </span>=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</div><div><span style=3D"white-space:pre"> <= /span>=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]/na= me() =3D 'Y' and *[2]/name() =3D 'X')) else</div><div><span= style=3D"white-space:pre"> </span>=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()"/&= gt;</div><div>=C2=A0 =C2=A0 =C2=A0 </xs:complexType></div><div>=C2=A0= =C2=A0</xs:element></div><div>=C2=A0 =C2=A0</div><div></xs:schema= ></div></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>Regards,<= br>Mukul Gandhi<br></div></div></div></div></div></div> --000000000000f6121a05a86a42d8--