PixelPaul
PixelPaul

Reputation: 2801

Using wildcards in XSD element names?

I have an XSD file as shown below. The problem is the nodes for City and State are dynamic, and will consist of actual City and State names. Is there any way to use a wildcard name for these elements?

<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified"
           elementFormDefault="qualified" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
  <xs:sequence>
    <xs:element minOccurs="0" name="State">
      <xs:complexType>
        <xs:sequence>
          <xs:element minOccurs="0" name="City">
            <xs:complexType>
              <xs:sequence>
                <xs:element minOccurs="0" name="cafeID" type="xs:string" />
                <xs:element minOccurs="0" name="cafeName" type="xs:string" />
                <xs:element minOccurs="0" name="cafeState" type="xs:string" />
                <xs:element minOccurs="0" name="cafeCity" type="xs:string" />
                <xs:element minOccurs="0" name="cafeStreetName" type="xs:string" />
                <xs:element minOccurs="0" name="cafeZip" type="xs:string" />
                <xs:element minOccurs="0" name="cafeContact" type="xs:string" />
                <xs:element minOccurs="0" name="cafeEmail" type="xs:string" />
                <xs:element minOccurs="0" name="hasPickup" type="xs:string" />
                <xs:element minOccurs="0" name="hasDriveThru" type="xs:string" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

Upvotes: 1

Views: 1062

Answers (1)

kjhughes
kjhughes

Reputation: 111726

Don't let element names vary across an unknown, open-ended domain because you'll frustrate efforts of

  1. Data modelers to constrain content models for these elements and of elements containing these elements.
  2. Consumers of this data to write handlers and transformations for these elements.

If you use XML as a markup language and markup the city and state names with city and state elements or attributes, you'll have much less trouble defining an XSD and creating applications for it.

Upvotes: 1

Related Questions