W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2013

Re: Adding restriction to a complexType

From: Mukul Gandhi <gandhi.mukul@gmail.com>
Date: Wed, 21 Aug 2013 20:28:27 +0530
Message-ID: <CABuuzNOXL9+AVqff7rohoTa0Pig2hG6=vq9xF+gE-CORW_D5wQ@mail.gmail.com>
To: "Hintz, David" <david.hintz@siemens.com>
Cc: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
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="productName">
     <xs:complexType>
       <xs:sequence>
          <xs:element name="name">
             <xs:simpleType>
                <xs:restriction base="xs:string">
                  <xs:minLength value="1"/>
                  <xs:maxLength value="255"/>
                </xs:restriction>
             </xs:simpleType>
          </xs:element>
          <xs:element ref="entityRef" minOccurs="0" maxOccurs="unbounded"/>
       <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 <david.hintz@siemens.com>wrote:

>  Hello,****
>
> ** **
>
> Using XML Schema 1.0, I’m having a problem trying to add a restriction to
> a complexType.  I’ve got this element definition:****
>
> ** **
>
>   <xs:element name="productName">****
>
>     <xs:simpleType>****
>
>       <xs:restriction base="xs:string">****
>
>         <xs:minLength value="1"/>****
>
>         <xs:maxLength value="255"/>****
>
>       </xs:restriction>****
>
>     </xs:simpleType>****
>
>   </xs:element>****
>
> ** **
>
> Obviously, I want “productName” to be a character string of 1 to 255
> characters.  Now, I’d like to add an element to “productName” – for example
> “entityRef” (0 to unbounded occurrences).  So, I’d need to change
> “productName” to <complexType mixed=”true”>, but I can’t figure out how to
> add the element and maintain the restriction for the overall length of
> “productName”.  This gets me close, but I lose the restriction:****
>
> ** **
>
>   <xs:element name="productName">****
>
>     <xs:complexType mixed="true">****
>
>       <xs:choice minOccurs="0" maxOccurs="unbounded">****
>
>         <xs:element ref="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****
>



-- 
Regards,
Mukul Gandhi
Received on Wednesday, 21 August 2013 14:59:15 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:16:05 UTC