XsdEditorNotation Alternative
In This Topic
Graphical Representation
Summary
An xs:element can have a number of xs:alternative's associated with it. When the xml is loaded the 'test' property on each <alternative> is evaluated. If it's true then that alternative is used in place of the parent element.
The definition of an xs:alternative is very similar that of an xs:element, however its base type must be a base type of the contained element.
Creating
An <alternative> can only be applied to an <element>, this can be done using the right click context menu on any of these entities.
Properties
Derived By |
|
Facets |
The facets available depend on the 'type' attribute see Facets for more information. |
Id |
A user defined ID to uniquely identify the entity within the schema |
Test |
The test carried out to see if this alternative definition will be applied. An XPath expression. |
XPath Default Namespace |
The default namespace applied to the 'Test' property |
Sample
The following XSD code
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Example">
<xs:complexType>
<xs:sequence>
<xs:element name="Beverage" type="BeverageType" maxOccurs="unbounded">
<xs:alternative test="@current-time <= '12:00:00'" type="MorningBeverage" />
<xs:alternative test="@current-time > '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:restriction base="BeverageType">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="tea" />
</xs:restriction>
</xs:simpleType>
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="AfternoonBeverage">
<xs:simpleContent>
<xs:restriction base="BeverageType">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="juice" />
</xs:restriction>
</xs:simpleType>
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
Will be represented like this
Sample XML would look like this
<?xml version="1.0" encoding="utf-8"?>
<Example>
<Beverage current-time="08:00:00">tea</Beverage>
<Beverage current-time="13:00:00">juice</Beverage>
</Example>
Inline Properties
Properties that apply to a type are shown inline at the bottom of the items container.
Values that are inherited from the base types are shown in brackets, values specifically set against the item are shown without brackets.
If a facet is not valid for a given type (typically because of its data type), then its value is shown in red.
Inline properties can be disabled in the
Options.