Adding restriction to a complexType

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding restriction to a complexType

Dave of Siemens

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

Reply | Threaded
Open this post in threaded view
|

Re: Adding restriction to a complexType

Michael Kay
<base href="x-msg://7459/">
It's not possible to restrict the text that appears within mixed content elements - except with XSD 1.1 assertions.

Michael Kay
Saxonica

On 20 Aug 2013, at 17:26, Hintz, David 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

DSL
Reply | Threaded
Open this post in threaded view
|

Re: Adding restriction to a complexType

DSL
In reply to this post by Dave of Siemens
Couldn't you do something like:

<xs:restriction base="xs:string">
    <xs:pattern value="[.]{1,255}"/>
</xs:restriction>




On Tue, Aug 20, 2013 at 12:26 PM, Hintz, David <[hidden email]> 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


Reply | Threaded
Open this post in threaded view
|

Re: Adding restriction to a complexType

Kopnicky, Lyle
In reply to this post by Dave of Siemens
Could you give an example of what you're trying to allow, and what you mean by "length" in the presence of mixed content?

I'm imagining you want something like this:

<productName>My Favorite Widget<entityRef ref="trademark"/></productName>

In that case, should the entityRef count as 1 toward the length? Or zero? Or should it be expanded into some text that is then measured?


On Tue, Aug 20, 2013 at 9:26 AM, Hintz, David <[hidden email]> 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




--
Lyle KopnickySoftware EngineerJanrain, Inc.
E: [hidden email] | W: 503-488-6754
Follow Janrain: Facebook | Twitter | YouTube | LinkedIn | Blog
-------------------------------------------------------------------------------------
Acquire, understand, and engage your users. Watch our video or sign up for a live demo to see what it's all about.
Reply | Threaded
Open this post in threaded view
|

RE: Adding restriction to a complexType

Dave of Siemens

I realize now what I’d like isn’t possible with XML Schema 1.0.  We’ll deal with the content length during processing.  But, yes, the count would include whatever the embedded element expands to.

 

From: Kopnicky, Lyle [mailto:[hidden email]]
Sent: Tuesday, August 20, 2013 3:18 PM
To: Hintz, David
Cc: [hidden email]
Subject: Re: Adding restriction to a complexType

 

Could you give an example of what you're trying to allow, and what you mean by "length" in the presence of mixed content?

 

I'm imagining you want something like this:

 

<productName>My Favorite Widget<entityRef ref="trademark"/></productName>

 

In that case, should the entityRef count as 1 toward the length? Or zero? Or should it be expanded into some text that is then measured?

 

On Tue, Aug 20, 2013 at 9:26 AM, Hintz, David <[hidden email]> 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



 

--
Lyle KopnickySoftware EngineerJanrain, Inc.
E: 
[hidden email] | W: 503-488-6754
Follow Janrain: 
Facebook | Twitter | YouTube | LinkedIn | Blog
-------------------------------------------------------------------------------------

Acquire, understand, and engage your users. Watch our video or sign up for a live demo to see what it's all about.

Reply | Threaded
Open this post in threaded view
|

Re: Adding restriction to a complexType

Mukul Gandhi
In reply to this post by Dave of Siemens
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 <[hidden email]> 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