0

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?

4

1 回答 1

1

您可以使用 xs:any 指定任何名称和类型。您的 XML 针对以下 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>
于 2013-04-27T17:46:57.840 回答