gpt4 book ai didi

java - 混合和受限元素无法通过 Xmlbeans 进行验证

转载 作者:行者123 更新时间:2023-11-30 05:02:16 26 4
gpt4 key购买 nike

在使用 Xmlbeans 时,我注意到当一个元素被定义为混合类型的限制时,如果该元素中有一些文本,则 Xmlbeans 验证会失败。但是,如果我运行它,则相同的 xml 文件是有效的XmlSpy 中的架构验证。这是示例(我试图使其尽可能简单):

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?

最佳答案

正如问题XMLBEANS-457中已经评论的那样您创建了 revision 1102771修复了问题。

关于java - 混合和受限元素无法通过 Xmlbeans 进行验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6279564/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com