Need Simple Element with Attribute & Restriction
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 5
- Joined: Wed Nov 28, 2007 7:45 pm
- Location: Omaha, Nebraska
Need Simple Element with Attribute & Restriction
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:
I tried to create a schema element like this, but OXygen says its's invalid. Can ayone see why?
:roll
Code: Select all
<speed units="kilometers-per-hour">100</speed>
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>
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post 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.
Regards,.
Sorin
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>
Sorin
-
- Posts: 107
- Joined: Mon Jul 30, 2007 11:31 pm
- Location: College Park, MD, United States
Things that should be simple
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

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
-- Zearin
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service