W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2001

Re: How to define an element with attribute

From: Eddie Robertsson <eddie@allette.com.au>
Date: Fri, 30 Mar 2001 17:02:24 +1000
Message-ID: <3AC42F80.DCEBAA2E@allette.com.au>
To: Wang K H <khong.hai.wang@gridnode.com>
CC: xmlschema-dev@w3.org


Wang K H wrote:

> Hi all, I am new to schema and is trying to write a schema. Please
> refer to the example below :<Value POSITION="4">PART</Value>
>
> How do I define the schema for the above element?
>
> Right now, I am writing as :
>
> <xsd:element name="Value" minOccurs="0" maxOccurs="unbounded">
>
> <xsd:complexType>
> <xsd:attribute name="POSITION" type="xsd:positiveInteger"
> use="optional"/>
>
> </xsd:complexType>
>
> </xsd:element>

<xsd:element name="Value" minOccurs="0" maxOccurs="unbounded">
   <xsd:complexType>
      <xsd:simpleContent>
         <xsd:extension base="xsd:string">
            <xsd:attribute name="POSITION" type="positiveInteger"
use="optional"/>
         </xsd:extension>
      </xsd:simpleContent>
   </xsd:complexType>
</xsd:element>

This will give you the element definition you want and in this case the
content of element Value is of type xsd:string.

Cheers,
/Eddie
Received on Friday, 30 March 2001 02:01:38 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:20 GMT