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

Re: simple attribute question

From: Jeni Tennison <jeni@jenitennison.com>
Date: Wed, 11 Aug 2004 21:29:26 +0100
Message-ID: <494515974.20040811212926@jenitennison.com>
To: Rob Harrington <robot252@yahoo.com>
CC: xmlschema-dev@w3.org

Hi Rob,

> In my schema definition, I simply want to express this
> xml:
>
> <item sometext="attributeText">9899</item>
>
> where 9899 is a positive integer.

<item> is an element with attributes whose content is a simple value.
Since it has attributes, it *must* have a complex type:

<xs:element name="item">
  <xs:complexType>
    ...
  </xs:complexType>
</xs:element>

but since it contains only text, it has simple content:

<xs:element name="item">
  <xs:complexType>
    <xs:simpleContent>
      ...
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

If the element was of a simple type, it would just have content, no
attributes. To create a type with attributes and simple content, you
have to *extend* the simple type to add the attribute:

<xs:element name="item">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:long">
        <xs:attribute name="sometext" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Wednesday, 11 August 2004 20:29:35 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 5 February 2014 07:15:10 UTC