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&#39;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 &lt;<a href=3D"mailto:gand=
[email protected]">[email protected]</a>&gt; 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&#39;=
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 &#39;maxOccurs&#39; cannot appear in element &#39;element&#39;.<br>[=
Error] query1.xsd:3:67: s4s-att-not-allowed: Attribute &#39;minOccurs&#39; =
cannot appear in element &#39;element&#39;.<br><br>i.e, the following is no=
t allowed by XSD language,<br><br>&lt;xs:schema attributeFormDefault=3D&quo=
t;unqualified&quot; elementFormDefault=3D&quot;qualified&quot; xmlns:xs=3D&=
quot;<a href=3D"http://www.w3.org/2001/XMLSchema" target=3D"_blank">http://=
www.w3.org/2001/XMLSchema</a>&quot;&gt;<br><br>=C2=A0 =C2=A0 &lt;xs:element=
 name=3D&quot;functionalView&quot; maxOccurs=3D&quot;1&quot; minOccurs=3D&q=
uot;1&quot;&gt;<br>=C2=A0 =C2=A0 ...<br><br>&lt;/xs:schema&gt;<br><br>Remov=
ing, maxOccurs=3D&quot;1&quot; minOccurs=3D&quot;1&quot; 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&#39;ve mentioned can =
be solved using an XSD 1.1 &lt;assert&gt; instruction. I guess that, you ca=
n rewrite your XSD fragment to following (I&#39;ve only added an &lt;assert=
&gt;), to achieve what you&#39;ve mentioned,<br><br>&lt;xs:element name=3D&=
quot;where&quot; maxOccurs=3D&quot;1&quot; minOccurs=3D&quot;0&quot;&gt;<br=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0&lt;xs:complexType&gt;<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0&lt;xs:sequence&gt;<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&lt;xs:element name=3D&quot;co=
ndition&quot; maxOccurs=3D&quot;unbounded&quot; minOccurs=3D&quot;1&quot;&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&lt;xs:complexType&gt;<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&lt;xs:simpleContent&gt;<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&lt;xs:extension base=3D&quot;xs:string&quot;&gt;<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 &lt;xs:attribute type=3D&quot;xs:string&quot; name=3D&quot;alias1&qu=
ot; use=3D&quot;required&quot;/&gt;<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 &lt;xs:attribute type=3D&quot=
;xs:string&quot; name=3D&quot;col1&quot; use=3D&quot;required&quot;/&gt;<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 &lt;xs:attribute type=3D&quot;xs:string&quot; name=3D&quot;operator&=
quot; use=3D&quot;required&quot;/&gt;<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 &lt;xs:attribute type=3D&quot=
;xs:string&quot; name=3D&quot;string&quot; use=3D&quot;optional&quot;/&gt;<=
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 &lt;xs:attribute type=3D&quot;xs:string&quot; name=3D&quot;numbe=
r&quot; use=3D&quot;optional&quot;/&gt;<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 &lt;xs:attribute type=3D&q=
uot;xs:string&quot; name=3D&quot;date&quot; use=3D&quot;optional&quot;/&gt;=
<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 &lt;xs:assert test=3D&quot;exists(@string | @number | @date)&quo=
t;/&gt;<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&lt;/xs:exten=
sion&gt;<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 &lt;/xs:simpleContent&gt;<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&lt;/xs:complexType&gt;<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:element&gt;<br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &lt;/xs:sequence&gt;<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&lt;/xs:complexType&gt;<div>&lt;/xs:element&=
gt;</div><div><br></div><div>I&#39;ve not tested, the logic of &lt;assert&g=
t; I&#39;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 &#39;test&#39; attribute of an &lt;assert&gt;. Also, 1 upto any numbe=
r of &lt;assert&gt; elements can be written as siblings in the XSD document=
 (all of the sibling &lt;assert&gt; 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 &lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt; 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 &lt;xs:element name=3D&quot;where&quot; maxO=
ccurs=3D&quot;1&quot; minOccurs=3D&quot;0&quot;&gt;<br>=C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 &lt;xs:complexType&gt;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 &lt;xs:sequence&gt;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 &lt;xs:element name=3D&quot;condition&quot; maxOccurs=3D&quot;unboun=
ded&quot; minOccurs=3D&quot;1&quot;&gt;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 &lt;xs:complexType&gt;<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &lt;xs:simpleContent&gt;<br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &lt;xs:exten=
sion base=3D&quot;xs:string&quot;&gt;<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&quot;xs=
:string&quot; name=3D&quot;alias1&quot; use=3D&quot;required&quot;/&gt;<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&quot;xs:string&quot; name=3D&quot;col1&quot; u=
se=3D&quot;required&quot;/&gt;<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&quot;xs:string=
&quot; name=3D&quot;operator&quot; use=3D&quot;required&quot;/&gt;<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&quot;xs:string&quot; name=3D&quot;string&quot; use=
=3D&quot;optional&quot;/&gt;<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&quot;xs:string&=
quot; name=3D&quot;number&quot; use=3D&quot;optional&quot;/&gt;<br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &lt;x=
s:attribute type=3D&quot;xs:string&quot; name=3D&quot;date&quot; use=3D&quo=
t;optional&quot;/&gt;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 &lt;/xs:extension&gt;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &lt;/xs:simpleContent&gt;<br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &lt;/xs:complexType&gt;<br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &lt;/xs:element&gt;<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &lt;/xs:sequence&gt;<br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 &lt;/xs:complexType&gt;<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 &lt;/xs:element&gt;<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--