Re: XSD with "required" attribute option related query
Rajneesh Shukla <[email protected]> Mon, 24 Feb 2020 13:39:38 +0530
| Newsgroups | gmane.text.xml.schema.devel |
|---|---|
| Message-ID | <CAFAat3-3+d6qJYPusL4qqEKMtE2mF3eTNdgdLLHr0pmSC_8cWw@mail.gmail.com> |
--0000000000000f8a95059f4de5c8 Content-Type: text/plain; charset="UTF-8" Hi Mukul, Thanks for your reply. I am working inside the database, it won't be possible. Oracle XML DB only supports XML Schema 1.0. Thanks, Rajneesh On Sat, 22 Feb 2020 at 11:27, Mukul Gandhi <[email protected]> wrote: > Hi Rajneesh, > Within the XSD document you've attached, following is a XSD issue to > start with (using Xerces-J 2.12.1 as XSD validator), > > [Error] query1.xsd:3:67: s4s-att-not-allowed: Attribute 'maxOccurs' cannot > appear in element 'element'. > [Error] query1.xsd:3:67: s4s-att-not-allowed: Attribute 'minOccurs' cannot > appear in element 'element'. > > i.e, the following is not allowed by XSD language, > > <xs:schema attributeFormDefault="unqualified" > elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema > "> > > <xs:element name="functionalView" maxOccurs="1" minOccurs="1"> > ... > > </xs:schema> > > Removing, maxOccurs="1" minOccurs="1" from above shown xs:element > declaration from your attached XSD document, makes your XSD document > correct (with both 1.0 and 1.1 versions of XSD language). > > Now coming to your question. > I think that, the issue you've mentioned can be solved using an XSD 1.1 > <assert> instruction. I guess that, you can rewrite your XSD fragment to > following (I've only added an <assert>), to achieve what you've mentioned, > > <xs:element name="where" maxOccurs="1" minOccurs="0"> > <xs:complexType> > <xs:sequence> > <xs:element name="condition" maxOccurs="unbounded" > minOccurs="1"> > <xs:complexType> > <xs:simpleContent> > <xs:extension base="xs:string"> > <xs:attribute type="xs:string" > name="alias1" use="required"/> > <xs:attribute type="xs:string" > name="col1" use="required"/> > <xs:attribute type="xs:string" > name="operator" use="required"/> > <xs:attribute type="xs:string" > name="string" use="optional"/> > <xs:attribute type="xs:string" > name="number" use="optional"/> > <xs:attribute type="xs:string" > name="date" use="optional"/> > <xs:assert > test="exists(@string | @number | @date)"/> > </xs:extension> > </xs:simpleContent> > </xs:complexType> > </xs:element> > </xs:sequence> > </xs:complexType> > </xs:element> > > I've not tested, the logic of <assert> I've mentioned above. > > Could be useful information to share that, you may use the full XPath 2.0 > language, to write value of 'test' attribute of an <assert>. Also, 1 upto > any number of <assert> elements can be written as siblings in the XSD > document (all of the sibling <assert> elements, have to evaluate to true > for having the XML instance document valid). > > On Fri, Feb 21, 2020 at 11:16 PM Rajneesh Shukla <[email protected]> > wrote: > >> Hello All, >> >> I am new to XSD and XML and need to explore if there is option to make >> sure that any one attribute in a set of attributes within same element is >> required. >> >> Example: >> >> <xs:element name="where" maxOccurs="1" minOccurs="0"> >> <xs:complexType> >> <xs:sequence> >> <xs:element name="condition" maxOccurs="unbounded" >> minOccurs="1"> >> <xs:complexType> >> <xs:simpleContent> >> <xs:extension base="xs:string"> >> <xs:attribute type="xs:string" name="alias1" >> use="required"/> >> <xs:attribute type="xs:string" name="col1" >> use="required"/> >> <xs:attribute type="xs:string" name="operator" >> use="required"/> >> <xs:attribute type="xs:string" name="string" >> use="optional"/> >> <xs:attribute type="xs:string" name="number" >> use="optional"/> >> <xs:attribute type="xs:string" name="date" >> use="optional"/> >> </xs:extension> >> </xs:simpleContent> >> </xs:complexType> >> </xs:element> >> </xs:sequence> >> </xs:complexType> >> </xs:element> >> >> Here I want to ensure that minimum one attribute in a set of 3 >> attributes (mentioned as optional in above) are required. All can not be >> optional , however any one (can be more than one also) is required. >> >> Thanking you in anticipation !!! >> >> Attachment: >> Complete XSD file. >> > > > > -- > Regards, > Mukul Gandhi > --0000000000000f8a95059f4de5c8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>Hi Mukul,</div><div><br></div><div>Thanks for your re= ply.</div><div> <p>I am=C2=A0 working inside the database, it won't be possible.</p><p>= Oracle XML DB only supports XML Schema 1.0.</p><p><br></p><p>Thanks,</p><p>= Rajneesh<br></p> </div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_= attr">On Sat, 22 Feb 2020 at 11:27, Mukul Gandhi <<a href=3D"mailto:gand= [email protected]">[email protected]</a>> wrote:<br></div><blockqu= ote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px= solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div dir=3D"ltr"= >Hi Rajneesh,=C2=A0<br></div>=C2=A0 =C2=A0 Within the XSD document you'= ve attached, following is a XSD issue to start with (using Xerces-J 2.12.1 = as XSD validator),<br><br>[Error] query1.xsd:3:67: s4s-att-not-allowed: Att= ribute 'maxOccurs' cannot appear in element 'element'.<br>[= Error] query1.xsd:3:67: s4s-att-not-allowed: Attribute 'minOccurs' = cannot appear in element 'element'.<br><br>i.e, the following is no= t allowed by XSD language,<br><br><xs:schema attributeFormDefault=3D&quo= t;unqualified" elementFormDefault=3D"qualified" xmlns:xs=3D&= quot;<a href=3D"http://www.w3.org/2001/XMLSchema" target=3D"_blank">http://= www.w3.org/2001/XMLSchema</a>"><br><br>=C2=A0 =C2=A0 <xs:element= name=3D"functionalView" maxOccurs=3D"1" minOccurs=3D&q= uot;1"><br>=C2=A0 =C2=A0 ...<br><br></xs:schema><br><br>Remov= ing, maxOccurs=3D"1" minOccurs=3D"1" from above shown x= s:element declaration from your attached XSD document, makes your XSD docum= ent correct (with both 1.0 and 1.1 versions of XSD language).<br><br>Now co= ming to your question.<br>I think that, the issue you've mentioned can = be solved using an XSD 1.1 <assert> instruction. I guess that, you ca= n rewrite your XSD fragment to following (I've only added an <assert= >), to achieve what you've mentioned,<br><br><xs:element name=3D&= quot;where" maxOccurs=3D"1" minOccurs=3D"0"><br= >=C2=A0 =C2=A0 =C2=A0 =C2=A0<xs:complexType><br>=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0<xs:sequence><br>=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<xs:element name=3D"co= ndition" maxOccurs=3D"unbounded" minOccurs=3D"1"&g= t;<br>=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<xs:complexType><br>=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<xs:simpleContent><br>=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<xs:extension base=3D"xs:string"><b= r>=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 <xs:attribute type=3D"xs:string" name=3D"alias1&qu= ot; use=3D"required"/><br>=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 <xs:attribute type=3D"= ;xs:string" name=3D"col1" use=3D"required"/><br= >=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 <xs:attribute type=3D"xs:string" name=3D"operator&= quot; use=3D"required"/><br>=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 <xs:attribute type=3D"= ;xs:string" name=3D"string" use=3D"optional"/><= br>=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 <xs:attribute type=3D"xs:string" name=3D"numbe= r" use=3D"optional"/><br>=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 <xs:attribute type=3D&q= uot;xs:string" name=3D"date" use=3D"optional"/>= <br>=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 <xs:assert test=3D"exists(@string | @number | @date)&quo= t;/><br>=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</xs:exten= sion><br>=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 </xs:simpleContent><br>=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</xs:complexType><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</xs:element><br>=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </xs:sequence><br>=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</xs:complexType><div></xs:element&= gt;</div><div><br></div><div>I've not tested, the logic of <assert&g= t; I've mentioned above.</div><div><br></div><div>Could be useful infor= mation to share that, you may use the full XPath 2.0 language, to write val= ue of 'test' attribute of an <assert>. Also, 1 upto any numbe= r of <assert> elements can be written as siblings in the XSD document= (all of the sibling <assert> elements, have to evaluate to true for = having the XML instance document valid).</div><div><br><div class=3D"gmail_= quote"><div dir=3D"ltr" class=3D"gmail_attr">On Fri, Feb 21, 2020 at 11:16 = PM Rajneesh Shukla <<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>> wrote:<br></div><blockquote cl= ass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid= rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">Hello All,<br><br>I am= new to XSD and XML and need to explore if there is option to make sure tha= t any one attribute in a set of attributes within same element is required.= <br><br>Example:<br><br>=C2=A0 <xs:element name=3D"where" maxO= ccurs=3D"1" minOccurs=3D"0"><br>=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 <xs:complexType><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 <xs:sequence><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 <xs:element name=3D"condition" maxOccurs=3D"unboun= ded" minOccurs=3D"1"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 <xs:complexType><br>=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <xs:simpleContent><br>=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <xs:exten= sion base=3D"xs:string"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <xs:attribute type=3D"xs= :string" name=3D"alias1" use=3D"required"/><br>= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 <xs:attribute type=3D"xs:string" name=3D"col1" u= se=3D"required"/><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <xs:attribute type=3D"xs:string= " name=3D"operator" use=3D"required"/><br>=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &= lt;xs:attribute type=3D"xs:string" name=3D"string" use= =3D"optional"/><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <xs:attribute type=3D"xs:string&= quot; name=3D"number" use=3D"optional"/><br>=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <x= s:attribute type=3D"xs:string" name=3D"date" use=3D&quo= t;optional"/><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 </xs:extension><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </xs:simpleContent><br>=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </xs:complexType><br>= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </xs:element><br>=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </xs:sequence><br>=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 </xs:complexType><br>=C2=A0 =C2=A0 =C2=A0 = =C2=A0 </xs:element><br><br><div>Here I want to ensure that minimum o= ne =C2=A0attribute =C2=A0in a set of 3 attributes (mentioned as optional in= above) are required. All can not be optional , however any one (can be mor= e than one also) is required.</div><div><br></div><div>Thanking you in anti= cipation !!!<br></div><div><br></div><div>Attachment:</div><div>Complete XS= D file.</div></div></blockquote><div>=C2=A0</div></div><br clear=3D"all"><d= iv><br></div>-- <br><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div= dir=3D"ltr"><div>Regards,<br>Mukul Gandhi</div></div></div></div></div></d= iv></div> </blockquote></div> --0000000000000f8a95059f4de5c8--