Xml Schema: Nodes with same name but different types based on attribute value

Midtown

New Member
I need a schema that accomplished this:\[code\]<object type="possession"> <property name="VIN">1111111111111111</property> <property name="Year">2003</property> <property name="Make">Chevrolet</property></object>\[/code\]
  • The "VIN" property must be 17 characters
  • The "Year property must be of type gYear
  • The "Make" property must conform to an enumeration of {Ford, Chevrolet, Mazda}
Right now I have this:\[code\]<?xml version="1.0" encoding="utf-8"?><xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="object"> <xs:complexType> <xs:choice maxOccurs="unbounded" minOccurs="0"> <xs:element name="property" maxOccurs="1" minOccurs="0" type="VinType"></xs:element> <xs:element name="property" maxOccurs="1" minOccurs="0" type="YearType"></xs:element> <xs:element name="property" maxOccurs="1" minOccurs="0" type="MakeType"></xs:element> </xs:choice> <xs:attribute name="type" type="xs:string" use="required" /> </xs:complexType> </xs:element> <!-- Vehicle Identification number (VIN) --> <xs:simpleType name="VinRestriction"> <xs:restriction base="xs:string"> <xs:length fixed="true" value="http://stackoverflow.com/questions/14592378/17"/> </xs:restriction> </xs:simpleType> <xs:complexType name="VinType" mixed="true"> <xs:simpleContent> <xs:extension base="VinRestriction"> <xs:attribute name="name" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="http://stackoverflow.com/questions/14592378/VIN" /> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:extension> </xs:simpleContent> </xs:complexType> <!-- Vehicle Year --> <xs:simpleType name="YearRestriction"> <xs:restriction base="xs:gYear"/> </xs:simpleType> <xs:complexType name="YearType" mixed="true"> <xs:simpleContent> <xs:extension base="YearRestriction"> <xs:attribute name="name" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="http://stackoverflow.com/questions/14592378/Year" /> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:extension> </xs:simpleContent> </xs:complexType> <!-- Vehicle Make --> <xs:simpleType name="MakeRestriction"> <xs:restriction base="xs:string"> <xs:enumeration value="http://stackoverflow.com/questions/14592378/Chevrolet"/> <xs:enumeration value="http://stackoverflow.com/questions/14592378/Ford"/> <xs:enumeration value="http://stackoverflow.com/questions/14592378/Mazda"/> </xs:restriction> </xs:simpleType> <xs:complexType name="MakeType" mixed="true"> <xs:simpleContent> <xs:extension base="MakeRestriction"> <xs:attribute name="name" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="http://stackoverflow.com/questions/14592378/Make" /> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:extension> </xs:simpleContent> </xs:complexType></xs:schema>\[/code\]
 
Back
Top