[thelist] xml scema confusion

Simon Watkins handymanorama at gmail.com
Fri Jul 3 02:31:18 CDT 2009


Hi all, I am trying to create an xml schema to validate some markup I have.
The markup (simplified) goes like:

<?xml version="1.0" encoding="utf-8"?>
<locations>
    <location>
        <placename>Somewhere</placename>
        <latitude>50.123456</latitude>
        <longitude>-2.123456</longitude>
    </location>
    <location>
        <placename>Other</placename>
    </location>
</locations>

 Each location must have a placename, and can optionally have a latitude and
longitude.  Obviously if it has one it has to have the other. It seems
logical to me to validate it against something like this, which has a choice
of a sequence, or merely an element:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="locations">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="unbounded" name="location">
          <xs:complexType>
            <xs:choice>
              <xs:sequence>
                <xs:element minOccurs="0" name="placename" type="xs:string"
/>
                <xs:element minOccurs="0" name="latitude" type="xs:decimal"
/>
                <xs:element minOccurs="0" name="longitude" type="xs:decimal"
/>
              </xs:sequence>
              <xs:element minOccurs="0" name="placename" type="xs:string" />
            </xs:choice>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

However this gives me this error (twice!):

"Multiple definition of element 'placename' causes the content model to
become ambiguous.  A content model must be formed such that during
validation of an element information item sequence, the particle contained
directly, indirectly or implicitly therein with which to attempt to validate
each item in the sequence in turn can be uniquely determined without
examining the content or attributes of that item, and without any
information about the items in the remainder of the sequence."

help?



More information about the thelist mailing list