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

发布于 11-14 14:37 字数 2172 浏览 3 评论 0原文

在使用 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?

while working with Xmlbeans, I have noticed that when an element is defined as a restriction from a mixed type, if there is some text in this element the Xmlbeans validation fails.However the same xml file is valid if I run it against schema validation in XmlSpy. Here is the example (I tried to make it as simple as possible):

xml schema:

<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 file:

<RootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Child>text</Child> 
    <ChildExtended>text1</ChildExtended>
    <ChildRestricted>text2</ChildRestricted>
</RootElement>

For XmlSpy, this is valid. Here's what I get when validating with 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"/>

As you can see, it is just the child defined as a restricted type that causes the problem. My question is : who is right ? XmlSpy (no error) or Xmlbeans ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罪#恶を代价2024-11-21 14:37:28

正如您创建的问题 XMLBEANS-457 中已评论的那样,修订版 1102771 修复了该问题。

As has already been commented in issue XMLBEANS-457 you created, revision 1102771 fixes the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文