xs:alternative & reuse?
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 1
- Joined: Wed Apr 15, 2020 5:14 am
xs:alternative & reuse?
Hello,
I have a complex bit of polymorphism I've achieved via xs:alternative in XSD 1.1. However, I'd like this weird amalgamated "type" I've created to be used in multiple elements. This is a problem, since as far as I can tell, the xs:alternative tag can only be a child of xs:element. Is there any way to do code re-use here, where I can have a the set of alternatives defined in a single place and multiple elements use it?
I have a complex bit of polymorphism I've achieved via xs:alternative in XSD 1.1. However, I'd like this weird amalgamated "type" I've created to be used in multiple elements. This is a problem, since as far as I can tell, the xs:alternative tag can only be a child of xs:element. Is there any way to do code re-use here, where I can have a the set of alternatives defined in a single place and multiple elements use it?
-
- Posts: 388
- Joined: Thu Jul 01, 2004 12:29 pm
Re: xs:alternative & reuse?
Hello,
You cannot reuse xs:alternative, you can reuse the types referred in the alternative. Here is an example:
Best Regards,
Octavian
You cannot reuse xs:alternative, you can reuse the types referred in the alternative. Here is an example:
Code: Select all
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">
<xs:element name="Example">
<xs:complexType>
<xs:sequence>
<xs:element name="Beverage" type="BeverageType" maxOccurs="unbounded">
<xs:alternative test="@current-time le '12:00:00'" type="MorningBeverage" />
<xs:alternative test="@current-time gt '12:00:00'" type="AfternoonBeverage" />
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="BeverageType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="current-time" type="xs:time" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="MorningBeverage">
<xs:simpleContent>
<xs:extension base="BeverageType">
<xs:attribute name="tea" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="AfternoonBeverage">
<xs:simpleContent>
<xs:extension base="BeverageType">
<xs:attribute name="juice" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
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