Re: Adding restriction to a complexType

Mukul Gandhi <[email protected]> Wed, 21 Aug 2013 20:28:27 +0530
Newsgroups gmane.text.xml.schema.devel
Message-ID <CABuuzNOXL9+AVqff7rohoTa0Pig2hG6=vq9xF+gE-CORW_D5wQ@mail.gmail.com>
--089e0160c3ec1ff57704e4766995
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

If you're bound to use XSD 1.0, a possible way is to modify the schema
according to XSD 1.0 language. Here's a possible solution with XSD 1.0,

<xs:element name=3D"productName">
     <xs:complexType>
       <xs:sequence>
          <xs:element name=3D"name">
             <xs:simpleType>
                <xs:restriction base=3D"xs:string">
                  <xs:minLength value=3D"1"/>
                  <xs:maxLength value=3D"255"/>
                </xs:restriction>
             </xs:simpleType>
          </xs:element>
          <xs:element ref=3D"entityRef" minOccurs=3D"0" maxOccurs=3D"unboun=
ded"/>
       <xs:sequence>
     </xs:complexType>
 </xs:element>

I've defined two sibling elements, and wrapped them within another element.

The above schema fragment can be varied according to the preferred style.
But if the text of complexType mixed content needs to be constrained, then
as has been written by Mike, using XSD 1.1 <assert> is a possible solution.


On Tue, Aug 20, 2013 at 9:56 PM, Hintz, David <[email protected]>wrot=
e:

>  Hello,****
>
> ** **
>
> Using XML Schema 1.0, I=92m having a problem trying to add a restriction =
to
> a complexType.  I=92ve got this element definition:****
>
> ** **
>
>   <xs:element name=3D"productName">****
>
>     <xs:simpleType>****
>
>       <xs:restriction base=3D"xs:string">****
>
>         <xs:minLength value=3D"1"/>****
>
>         <xs:maxLength value=3D"255"/>****
>
>       </xs:restriction>****
>
>     </xs:simpleType>****
>
>   </xs:element>****
>
> ** **
>
> Obviously, I want =93productName=94 to be a character string of 1 to 255
> characters.  Now, I=92d like to add an element to =93productName=94 =96 f=
or example
> =93entityRef=94 (0 to unbounded occurrences).  So, I=92d need to change
> =93productName=94 to <complexType mixed=3D=94true=94>, but I can=92t figu=
re out how to
> add the element and maintain the restriction for the overall length of
> =93productName=94.  This gets me close, but I lose the restriction:****
>
> ** **
>
>   <xs:element name=3D"productName">****
>
>     <xs:complexType mixed=3D"true">****
>
>       <xs:choice minOccurs=3D"0" maxOccurs=3D"unbounded">****
>
>         <xs:element ref=3D"entityRef"/>****
>
>       </xs:choice>****
>
>     </xs:complexType>****
>
>   </xs:element>****
>
> ** **
>
> Anyone have a simple solution for maintaining the restriction of 1-255
> characters in length?  Or, is this even possible?****
>
> ** **
>
> Thanks,****
>
> ** **
>
> Dave Hintz****
>
> Siemens****
>



--=20
Regards,
Mukul Gandhi

--089e0160c3ec1ff57704e4766995
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>If you&#39;re bound to use XSD 1.0, a possible way is=
 to modify the schema according to XSD 1.0 language. Here&#39;s a possible =
solution with XSD 1.0,<br><br>&lt;xs:element name=3D&quot;productName&quot;=
&gt;<br>

=A0=A0=A0=A0 &lt;xs:complexType&gt;<br>=A0=A0=A0 =A0=A0 &lt;xs:sequence&gt;=
<br>=A0=A0=A0 =A0=A0=A0 =A0 &lt;xs:element name=3D&quot;name&quot;&gt;<br>=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &lt;xs:simpleType&gt;<br>=A0=A0=A0 =A0=
=A0=A0 =A0=A0=A0 =A0=A0=A0 &lt;xs:restriction base=3D&quot;xs:string&quot;&=
gt;<br>

=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 &lt;xs:minLength value=3D&quot;=
1&quot;/&gt;<br>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 &lt;xs:maxLengt=
h value=3D&quot;255&quot;/&gt;<br>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 &=
lt;/xs:restriction&gt;<br>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0&lt;/xs:simpleTy=
pe&gt;<br>=A0=A0=A0 =A0=A0=A0 =A0 &lt;/xs:element&gt;<br>

=A0=A0=A0 =A0=A0=A0 =A0 &lt;xs:element ref=3D&quot;entityRef&quot; minOccur=
s=3D&quot;0&quot; maxOccurs=3D&quot;unbounded&quot;/&gt;<br>=A0=A0=A0=A0=A0=
=A0 &lt;xs:sequence&gt;<br>=A0=A0=A0=A0 &lt;/xs:complexType&gt;<br>=A0&lt;/=
xs:element&gt;<br><br></div><div>I&#39;ve defined two sibling elements, and=
 wrapped them within another element.<br>

</div><div><br></div>The above schema fragment can be varied according to t=
he preferred style. But if the text of complexType mixed content needs to b=
e constrained, then as has been written by Mike, using XSD 1.1 &lt;assert&g=
t; is a possible solution.<br>

<div><div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On =
Tue, Aug 20, 2013 at 9:56 PM, Hintz, David <span dir=3D"ltr">&lt;<a href=3D=
"mailto:[email protected]" target=3D"_blank">[email protected]<=
/a>&gt;</span> wrote:<br>

<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 link=3D"blue" vlink=3D"purple" lang=3D"EN-US">
<div>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">Hello,<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;"><u></u>=A0<u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">Using XML Schema 1.0, I=92m having a problem trying =
to add a restriction to a complexType. =A0I=92ve got this element definitio=
n:<u></u><u></u></span></p>


<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;"><u></u>=A0<u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0 &lt;xs:element name=3D&quot;productName&quot;&gt=
;<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0=A0=A0 &lt;xs:simpleType&gt;<u></u><u></u></span>=
</p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0=A0=A0=A0=A0 &lt;xs:restriction base=3D&quot;xs:s=
tring&quot;&gt;<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0=A0=A0=A0=A0=A0=A0 &lt;xs:minLength value=3D&quot=
;1&quot;/&gt;<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0=A0=A0=A0=A0=A0=A0 &lt;xs:maxLength value=3D&quot=
;255&quot;/&gt;<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0=A0=A0=A0=A0 &lt;/xs:restriction&gt;<u></u><u></u=
></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0=A0=A0 &lt;/xs:simpleType&gt;<u></u><u></u></span=
></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0 &lt;/xs:element&gt;<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;"><u></u>=A0<u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">Obviously, I want =93productName=94 to be a characte=
r string of 1 to 255 characters.=A0 Now, I=92d like to add an element to =
=93productName=94 =96 for example =93entityRef=94 (0 to unbounded
 occurrences).=A0 So, I=92d need to change =93productName=94 to &lt;complex=
Type mixed=3D=94true=94&gt;, but I can=92t figure out how to add the elemen=
t and maintain the restriction for the overall length of =93productName=94.=
=A0 This gets me close, but I lose the restriction:<u></u><u></u></span></p=
>


<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;"><u></u>=A0<u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0 &lt;xs:element name=3D&quot;productName&quot;&gt=
;<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0=A0=A0 &lt;xs:complexType mixed=3D&quot;true&quot=
;&gt;<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0=A0=A0=A0=A0 &lt;xs:choice minOccurs=3D&quot;0&qu=
ot; maxOccurs=3D&quot;unbounded&quot;&gt;<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0=A0=A0=A0=A0=A0=A0 &lt;xs:element ref=3D&quot;ent=
ityRef&quot;/&gt;<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0=A0=A0=A0=A0 &lt;/xs:choice&gt;<u></u><u></u></sp=
an></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0=A0=A0 &lt;/xs:complexType&gt;<u></u><u></u></spa=
n></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">=A0 &lt;/xs:element&gt;<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;"><u></u>=A0<u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">Anyone have a simple solution for maintaining the re=
striction of 1-255 characters in length?=A0 Or, is this even possible?<u></=
u><u></u></span></p>


<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;"><u></u>=A0<u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">Thanks,<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;"><u></u>=A0<u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">Dave Hintz<u></u><u></u></span></p>
<p class=3D""><span style=3D"font-size:10pt;font-family:&quot;Arial&quot;,&=
quot;sans-serif&quot;">Siemens<u></u><u></u></span></p>
</div>
</div>

</blockquote></div><br><br clear=3D"all"><br>-- <br>Regards,<br>Mukul Gandh=
i
</div></div></div></div>

--089e0160c3ec1ff57704e4766995--