[
Lists Home |
Date Index |
Thread Index
]
What you need is to define a complex type with simple content:
<xsd:complexType name="widthType">
<xsd:simpleContent>
<xsd:extension base="xsd:decimal">
<xsd:attribute name="units" type="xsd:string" use="optional"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
Then declare the element as that type:
<xsd:element name="width" type="widthType" />
Check out Roger Costello's tutorial. It should answer many of these type
of questions.
http://www.xfront.com/xml-schema.html
-rick
At 10:47 AM 5/15/03 -0500, Richard Rowell wrote:
>I'm sure the answer is painfully obvious, but I cant figure out how to
>add an attribute to an element. I want a structure like this:
>
><box>
> <size>
> <width units='cm'>50</width>
> <height units='m'>1</width>
> </size>
></box>
>
>AFAICT I can only attach attributes to complex types in XMLSchema, but
>width and height are not complex types (are they?). I know how to
>attach the "units" attribute to the size element, but I don't want it
>there. This is what I have tried:
>
><xsd:element name="size">
> <xsd:complexType>
> <xsd:all>
> <xsd:element name="width" type="xsd:integer" minOccurs='1'
>maxOccurs='1'>
> <xsd:attribute name='units' type="xsd:string"/>
> </xsd:element>
> <xsd:element name="height" type="xsd:integer" minOccurs='1'
>maxOccurs='1'/>
> </xsd:all>
> </xsd:complexType>
> </xsd:element>
>
>Xerces rejects this though:
>** Schema error: src-element.0: the content of an element information
>item must match (annotation?, (simpleType | complexType)?, (unique | key
>| keyref)*). **
>LINE: 1
>PUBLIC_ID: null
>SYSTEM_ID:
>
>--
>Richard Rowell <richard@bowmansystems.com>
Rick Taylor
XML Developer
PPDM Association
|