【问题标题】:XSD error: Element is a simple type, so it must have no element information item [children]XSD错误:元素是简单类型,所以它必须没有元素信息项[children]
【发布时间】:2016-09-25 17:19:51
【问题描述】:

我正在研究一个非常基本的 XML 模式并且我正在接收

cvc-type.3.1.2:元素'creator'是一个简单类型,所以它必须没有 元素信息项 [children]。 [8]

当我尝试验证 XML 时在 NetBeans 中。我正在关注 W3 学校教程,看来我的代码与他们的非常相似。当我将错误状态创建者声明为复杂类型时,我感到很困惑。我是否错误地将创建者元素声明为复杂类型?

XML 文档:

<?xml version="1.0" encoding="UTF-8" ?>
<gallery
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="Proj1Schema.xsd">
    <creator>
        <name>John Doe</name>
    </creator>
</gallery>

架构:

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="http://xml.netbeans.org/schema/gallery"
    elementFormDefault="qualified">

    <xs:element name="creator">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="name" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
    </xs:element>

    <xs:element name="gallery">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="creator" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

【问题讨论】:

    标签: xml xsd xsd-validation xml-validation


    【解决方案1】:

    替换

                <xs:element name="creator" type="xs:string"/>
    

                <xs:element ref="creator"/>
    

    gallery 的内容模型中重用element 的全局声明。正如您拥有 XSD 一样,gallery 中的 creator 只允许简单的 xs:string 内容,这与您的 XML 具有复杂内容(包括 name 子元素)相反。

    【讨论】:

    • 你已经对我说清楚了。感谢您分享你的知识! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    相关资源
    最近更新 更多