Page 1 of 1
Need Simple Element with Attribute & Restriction
Posted: Wed Nov 28, 2007 7:55 pm
by husker
I'm trying to crete a schema definition for a simple data type that has both an attribute & a restriction. For example, in the XML instance document, the element might look like this:
Code: Select all
<speed units="kilometers-per-hour">100</speed>
I tried to create a schema element like this, but OXygen says its's invalid. Can ayone see why?
Code: Select all
<xsd:simpleType name="Speed">
<xsd:restriction base="xsd:nonNegativeInteger" >
<xsd:maxInclusive value="999"/>
</xsd:restriction>
<xsd:attribute name="units" default="miles-per-hour"/>
</xsd:simpleType>
:roll
Posted: Thu Nov 29, 2007 12:55 pm
by sorin_ristache
Hello,
W3C XML Schema does not allow an attribute in a simple type or a restriction of a simple type inside a complex type. You have to define the restriction in a separate simple type and extend it with the attribute in a new complex type.
Code: Select all
<xsd:simpleType name="SpeedValuesType">
<xsd:restriction base="xsd:nonNegativeInteger">
<xsd:maxInclusive value="999"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="SpeedType">
<xsd:simpleContent>
<xsd:extension base="SpeedValuesType">
<xsd:attribute name="units" default="miles-per-hour"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
Regards,.
Sorin
Posted: Thu Nov 29, 2007 3:44 pm
by husker
That did it! Things that should be simple never are!
Things that should be simple
Posted: Thu Jan 10, 2008 7:57 pm
by Zearin
If you're looking for simple, than I recommend ditching XML Schema.
Relax NG is much more writable AND readable, and Relax NG Compact even moreso. Take a look here and see how easy it is to read these schemas:
http://relaxng.org/compact-tutorial-20030326.html
And no functionality is lost. Using Oxygen's Trang converter you can write and read schema definitions in the way-simpler Relax NG Compact and convert them to XSD for validation and compatibility with other XML tools.
Good luck!
-- Zearin