【问题标题】:Element 'price' cannot have character [children], because the type's content type is element-only元素 'price' 不能有字符 [children],因为该类型的内容类型是 element-only
【发布时间】:2013-05-13 09:55:13
【问题描述】:

我正在尝试根据我的 XML 架构验证我的 XML 文件,但是对于我的 XML 文件中的每个项目,我收到以下两个错误:

cvc-complex-type.2.3:元素“价格”不能有字符 [children],因为该类型的内容类型是仅元素。

cvc-complex-type.2.4.b:元素'price'的内容不完整。应为 '{"":one_and_half_litre}' 之一。

以下是 XML 文件的示例:

<soft_drinks>
    <drink>
        <name>Coca Cola</name>
        <price>â¬1.60</price>
    </drink>
    <drink>
        <name>Coca Cola Zero</name>
        <price>â¬1.60</price>
    </drink>
    <drink>
        <name>Coca Cola Diet</name>
        <price>â¬1.60</price>
    </drink>
    <drink>
        <name>Sprite</name>
        <price>â¬1.60</price>
    </drink>
    <drink>
        <name>Sprite Zero</name>
        <price>â¬1.60</price>
    </drink>
    <drink>
        <name>Fanta Orange</name>
        <price>â¬1.60</price>
    </drink>
    <drink>
        <name>Fanta Lemon</name>
        <price>â¬1.60</price>
    </drink>
</soft_drinks>

下面是 XML Schema 的一部分:

<xs:element name="soft_drinks">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="drink" maxOccurs="unbounded" minOccurs="0">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="name" type="xs:string"/>
                                <xs:element name="price">
                                </xs:element>
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:complexType>
        </xs:element>

如果您能提供帮助,谢谢! :)

【问题讨论】:

  • 您的架构需要在您的 节点下满足您的饮料尺寸的节点。不同的尺寸可能有不同的价格。
  • 如果在price 上也指定type="xs:string" 会发生什么?
  • 你的问题是什么?帮忙做什么?错误消息在我看来是正确的,您需要什么帮助?翻译它们?

标签: xml validation web schema


【解决方案1】:

我认为你需要补充:

type="xs:string"

到价格元素。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2017-06-20
    • 2021-08-29
    • 2020-08-25
    • 2021-03-17
    • 2022-08-17
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    • 2021-04-20
    相关资源
    最近更新 更多