[
Lists Home |
Date Index |
Thread Index
]
In XML Schema, you can add attributes to an element with simple content
using an anonymous complex type as a child of the element declaration.
Something like will work:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="foo">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="xs:string">
<xs:enumeration value="fizz"/>
<xs:enumeration value="fuzz"/>
</xs:restriction>
</xs:simpleContent>
<xs:attribute name="bar" type="Bar"/>
</xs:complexType>
</xs:element>
<xs:simpleType name="Bar">
<xs:restriction base="xs:string">
<xs:enumeration value="glorp"/>
<xs:enumeration value="glop"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
The syntax for RELAX NG (12 lines) is somewhat simpler than the XML Schema
syntax (18 lines). For example:
<element name="foo" xmlns="http://relaxng.org/ns/structure/1.0">
<attribute name="bar">
<choice>
<value>glorp</value>
<value>glop</value>
</choice>
</attribute>
<choice>
<value>fizz</value>
<value>fuzz</value>
</choice>
</element>
Here is a valid instance for both schemas, tested with MSV:
<?xml version="1.0"?>
<foo bar="glorp">fuzz</foo>
Mike
-----Original Message-----
From: Morgan V. Cundiff [mailto:mcundiff@loc.gov]
Sent: Wednesday, March 06, 2002 8:18 AM
To: xml-dev@lists.xml.org
Subject: [xml-dev] schema content model question
I have been attempting to create an XML Schema content model for an
element like the following:
- the element should contain text only, no subeleemnts (simpleContent?)
- the permissable values of the element should be restricted to a list of
enumerated string values
- the element should also have attributes with values which are also
restricted to list of enumerated string values.
Is this possible? I have made several attempts which I will send if it is
useful for discussion but I thought perhaps someone can just provide the
answer.
thanks,
Morgan Cundiff
Library of Congress
-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
initiative of OASIS <http://www.oasis-open.org>
The list archives are at http://lists.xml.org/archives/xml-dev/
To subscribe or unsubscribe from this list use the subscription
manager: <http://lists.xml.org/ob/adm.pl>
|