在使用 Xmlbeans 时,我注意到当一个元素被定义为来自混合类型的限制时,如果此元素中有一些文本,则 Xmlbeans 验证失败。但是,如果我针对架构验证运行相同的 xml 文件,则它是有效的Xml间谍。这是示例(我试图使其尽可能简单):
xml架构:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="RootElement">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="Child"/>
<xs:element ref="ChildExtended"/>
<xs:element ref="ChildRestricted"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Child" type="MixedType"/>
<xs:element name="ChildRestricted" type="MixedTypeRestricted"/>
<xs:element name="ChildExtended" type="MixedTypeExtended"/>
<xs:complexType name="MixedType" mixed="true"/>
<xs:complexType name="MixedTypeExtended" mixed="true">
<xs:complexContent mixed="true">
<xs:extension base="MixedType"/>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="MixedTypeRestricted" mixed="true">
<xs:complexContent mixed="true">
<xs:restriction base="MixedType"/>
</xs:complexContent>
</xs:complexType>
</xs:schema>
xml文件:
<RootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Child>text</Child>
<ChildExtended>text1</ChildExtended>
<ChildRestricted>text2</ChildRestricted>
</RootElement>
对于 XmlSpy,这是有效的。这是使用 Xmlbeans 验证时得到的结果:
Message: Element 'ChildRestricted' with empty content type cannot have text or element content.
Location of invalid XML: <xml-fragment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
如您所见,只是定义为受限类型的子项导致了问题。我的问题是:谁是对的?XmlSpy(无错误)或 Xmlbeans ?