Razer
Razer

Reputation: 8211

XSD: Define element with any type and any name

I have following XML structure:

<?xml version="1.0" encoding="utf-8"?>
<DataSets>
  <DataSet>
    <Parameter id="1"/>
    <Parameter Description="My Description"/>
    <Parameter value="3.14"/>
  </DataSet>
  <DataSet>
    <Parameter id="2"/>
    <Parameter timeout="123"/>
  </DataSet>
</DataSets>

For validation I want to create a XSD schema. The most inner element Parameter can by any type with any name. There must be at least one of such element.

How to define the XSD scheme for this inner element?

Upvotes: 0

Views: 1531

Answers (1)

Matthias Herlitzius
Matthias Herlitzius

Reputation: 3395

You can use xs:any to specify any name and type. Your XML validates against the following XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

    <xs:element name="DataSets" type="dataSets"/>

    <xs:complexType name="dataSets">
        <xs:sequence>
            <xs:element name="DataSet" type="dataSet" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="dataSet">
        <xs:sequence>
            <xs:any minOccurs="1" maxOccurs="unbounded" namespace="##any" processContents="lax" />
        </xs:sequence>
    </xs:complexType>

</xs:schema>

Upvotes: 1

Related Questions