请尝试以下使用条件类型分配 (CTA) 的 XSD 1.1。
XML
<doc id="JOURNAL/otai/04.03/product/root">
<field name="name1">8043501d8766ee1199370022482955e0</field>
<field name="name2">false</field>
<field name="name3">2023-10-09T09:35:00Z</field>
</doc>
XSD 1.1
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="doc">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="field"/>
</xs:sequence>
<xs:attribute name="id" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="field" type="xs:anySimpleType">
<xs:alternative test="@name eq 'name1'" type="StringType"/>
<xs:alternative test="@name eq 'name2'" type="BooleanType"/>
<xs:alternative test="@name eq 'name3'" type="DateTimeType"/>
<xs:alternative type="xs:error"/>
</xs:element>
<xs:complexType name="StringType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" use="required" type="NameAttrType"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="BooleanType">
<xs:simpleContent>
<xs:extension base="xs:boolean">
<xs:attribute name="name" use="required" type="NameAttrType"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="DateTimeType">
<xs:simpleContent>
<xs:extension base="xs:dateTime">
<xs:attribute name="name" use="required" type="NameAttrType"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="NameAttrType">
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:maxLength value="100"/>
<xs:enumeration value="name1"/>
<xs:enumeration value="name2"/>
<xs:enumeration value="name3"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>