Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML schema and OO Overriding

Status
Not open for further replies.

courtis

Programmer
Aug 4, 2005
1
CA
How do I override an element with out losing my inheritance? Using the following:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="vehicles">
		<xs:annotation>
			<xs:documentation>Comment describing your root element</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="car"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="car" type="carType"/>
	<xs:complexType name="vehicleType">
		<xs:all>
			<xs:element name="type">
				<xs:simpleType>
					<xs:restriction base="xs:string">
						<xs:enumeration value="car"/>
						<xs:enumeration value="motorcycle"/>
						<xs:enumeration value="truck"/>
						<xs:enumeration value="boat"/>
					</xs:restriction>
				</xs:simpleType>
			</xs:element>
			<xs:element name="transmissiontype">
				<xs:simpleType>
					<xs:restriction base="xs:string">
						<xs:enumeration value="manual"/>
						<xs:enumeration value="automatic"/>
					</xs:restriction>
				</xs:simpleType>
			</xs:element>
			<xs:element name="numberofwheels">
				<xs:simpleType>
					<xs:restriction base="xs:decimal">
						<xs:minInclusive value="2"/>
						<xs:maxInclusive value="18"/>
					</xs:restriction>
				</xs:simpleType>
			</xs:element>
		</xs:all>
	</xs:complexType>
	<xs:complexType name="carType">
		<xs:complexContent>
			<xs:extension base="vehicleType"/>
		</xs:complexContent>
	</xs:complexType>
</xs:schema>
If I wanted to override type so that it had a fixed value of car and the maxInclusive on numberofwheels to be 4, I could make the element car a restriction of carType like so:
Code:
	<xs:element name="car">
		<xs:complexType>
			<xs:complexContent>
				<xs:restriction base="carType">
					<xs:all>
						<xs:element name="type" fixed="car">
							<xs:simpleType>
								<xs:restriction base="xs:string"/>
							</xs:simpleType>
						</xs:element>
						<xs:element name="transmissiontype">
							<xs:simpleType>
								<xs:restriction base="xs:string">
									<xs:enumeration value="manual"/>
									<xs:enumeration value="automatic"/>
								</xs:restriction>
							</xs:simpleType>
						</xs:element>
						<xs:element name="numberofwheels">
							<xs:simpleType>
								<xs:restriction base="xs:decimal">
									<xs:minInclusive value="2"/>
									<xs:maxInclusive value="4"/>
								</xs:restriction>
							</xs:simpleType>
						</xs:element>
					</xs:all>
				</xs:restriction>
			</xs:complexContent>
		</xs:complexType>
	</xs:element>
However if I go back to vehicleType and add another element like lights I have to also go back and add it to the restriction elements too, car in this case.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top