Russ wrote:
Suppose I want to specify a position on the earth. I could define an
element such as
<position coords="WGS84", lat="34.56223", lon="-121.8277"/>
^^^ ^^^
I am not sure why you have those commas, that is not well-formed.
where lat and lon are latitude and longitude in the WGS84 coordinate
system. Now suppose I also want to have the option of specifying the
position in another coordinate system, a locally level cartesian
system. I could define an element such as
<position coords="DFW", x="236.764", y="129.667"/>
where "DFW" is a predefined coordinate system.
I'm new to XML, and I'd like to know if it is possible to define a
schema that would enforce consistency for both options and perhaps
others as well. The trick here is that for the WGS84 coordinate
system, the coordinate attributes are lat and lon, whereas for the DFW
system they are x and y. Is it possible to write a schema to require
this?
Well, it is easy to define an element where the coords attribute is
mandatory and the other optional, e.g. a document alike
<?xml version="1.0" encoding="UTF-8"?>
<positions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test20040208Xsd.xml ">
<position coords="WGS84" lat="34.56223" lon="-121.8277" />
<position coords="DFW" x="236.764" y="129.667" />
</positions>
then validates against
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="positions">
<xs:complexType>
<xs:sequence>
<xs:element ref="position" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="position">
<xs:complexType>
<xs:attribute name="coords" type="coordsType" use="required" />
<xs:attribute name="lat" type="xs:double" />
<xs:attribute name="lon" type="xs:double" />
<xs:attribute name="x" type="xs:double" />
<xs:attribute name="y" type="xs:double" />
</xs:complexType>
</xs:element>
<xs:simpleType name="coordsType">
<xs:restriction base="xs:string">
<xs:enumeration value="WGS84" />
<xs:enumeration value="DFW" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
That is not very restrictive however as you could also have an element
<position coords="DFW" lat="42" lon="42" />
You might want to choose a different structure than putting all
information in attributes.
--
Martin Honnen
http://JavaScript.FAQTs.com/