Xml 用于重复具有不同子元素的元素的XSD
嗨,我有一个xml,看起来像Xml 用于重复具有不同子元素的元素的XSD,xml,xsd,repeat,xsd-validation,Xml,Xsd,Repeat,Xsd Validation,嗨,我有一个xml,看起来像 <ABC> <DEF Value="123"> <XYZ> <RootEle Text="Now" Date="SomeDate"/> </XYZ> </DEF> <DEF AnotherValue="123"> <XYZ> <AnotherRootEle AnotherText="NowOrNever" AnotherDate="SomeOtherDate"/&
<ABC>
<DEF Value="123">
<XYZ>
<RootEle Text="Now" Date="SomeDate"/>
</XYZ>
</DEF>
<DEF AnotherValue="123">
<XYZ>
<AnotherRootEle AnotherText="NowOrNever" AnotherDate="SomeOtherDate"/>
</XYZ>
</DEF>
</ABC>
我需要为此编写一个xsd。但我编写的xsd对上述xml并不适用
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="ABC">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="1">
<xsd:element name="DEF">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="unbounded">
<xsd:element name="XYZ">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="1">
<xsd:element name="RootEle">
<xsd:complexType>
<xsd:attribute name="Text" use="optional">
<xsd:annotation>
<xsd:documentation>Text</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="40" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Date" use="optional">
<xsd:annotation>
<xsd:documentation>Date</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="40" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="Value" use="optional">
<xsd:annotation>
<xsd:documentation>Name of the flow</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="40" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="AnotherValue" use="optional">
<xsd:annotation>
<xsd:documentation>Name of interface</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="40" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
正文
日期
流的名称
接口名称
上面的xsd适用于下面的xml,但不适用于首先发布的xml,即它不适用于具有不同子元素的重复元素
<ABC>
<DEF Value="123">
<XYZ>
<RootEle Text="Now" Date="SomeDate"/>
</XYZ>
</DEF>
</ABC>
sergioFC对此的任何帮助都是正确的,他的评论是正确的。您将事件定义为错误的级别 而不是
<xsd:element name="DEF">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="unbounded">
你应该
<xsd:element minOccurs="1" maxOccurs="unbounded" name="DEF">
<xsd:complexType>
<xsd:sequence>
但是,XML中还有一个根本不出现在XSD中的rootele
为此,您需要使用以下选项重新定义XYZ
<xsd:element name="XYZ">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="1">
<xsd:choice minOccurs="0">
<xsd:element name="RootEle">
<xsd:complexType>
<xsd:attribute name="Text" use="optional">
<xsd:annotation>
<xsd:documentation>Text</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="40" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Date" use="optional">
<xsd:annotation>
<xsd:documentation>Date</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="40" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="AnotherRootEle">
<xsd:complexType>
<xsd:attribute name="AnotherText" use="optional">
<xsd:annotation>
<xsd:documentation>Text</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="40" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="AnotherDate" use="optional">
<xsd:annotation>
<xsd:documentation>Date</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="40" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
正文
日期
正文
日期
看起来DEF
元素应该有一些修改;你现在看到的是,一个DEF
可以有很多XYZ
孩子。