views:

35

answers:

1

Hi! Just to be concise I want to obtain something like this:

<root>
    <field value="..." text="...">fixed_value1</field>
    <field value="..." text="...">fixed_value2</field>
    <field value="..." text="...">fixed_value3</field>
    <!-- in some cases we can choose the «fixed_value» among different ones -->
    ...
    <field value="..." text="...">fixed_valueN</field>
</root>

I tried different ways but it seems quite impossible to achive that, because XML Schema does not allow to set a list of elements with the same name, but different types (Simple or Complex doesn't matter...). Is it right? There's no other way to define a structure like above?

EDIT: maybe I have to explain it a little bit better. Between the open and close tag of element «field» there must be a value defined by the XML Schema (in other words for the user it's not possible to write something different from the fixed_value). Another example:

<root>
    <field value="Ferrari" text="company">Car</field>
    <!-- but it could be Van or Motorcycle or Plane -->
    <field value="12300000" text="euro">Cost</field>
    <!-- here instead it's only possible to choose «Cost» -->
    <field value="Red" text="">Color</field>
    <!-- same as above -->
</root>

Is that possible? Thanks in advance!

A: 

Try the following XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="root" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  <xs:element name="root">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="field" nillable="true">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute name="value" type="xs:string" />
                <xs:attribute name="text" type="xs:string" />
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>
Wim Hollebrandse