【问题标题】:XSD Validation Failed: Element has both a 'type' attribute and a 'anonymous type' child. Only one of these is allowed for an elementXSD 验证失败:元素同时具有“类型”属性和“匿名类型”子项。一个元素只允许使用其中一个
【发布时间】:2015-06-23 06:37:56
【问题描述】:

当我验证 XSD 文件时,它会给出以下错误

"src-element.3: 元素'Account'既有'type'属性又有'anonymous type'子元素。元素只允许使用其中一个。"

<xsd:element name="AccountDetailsResponse">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="Account" type="account:Account">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="ID">
                            <xsd:complexType>
                                <xsd:sequence>
                                    <xsd:element type="xsd:string" name="NAME"/>
                                    <xsd:element type="xsd:string" name="PHONE"/>
                                    <xsd:element type="xsd:string" name="CATEGORY"/>
                                    <xsd:element type="xsd:int" name="LASTMODIFIED"/>
                                </xsd:sequence>
                            </xsd:complexType>
                        </xsd:element>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

请帮助解决并使其成为有效的 xsd。

谢谢

【问题讨论】:

    标签: xml xslt xsd xml-parsing xsd-validation


    【解决方案1】:

    你已经得到了答案。你有两个选择:

    • 从名称为“Account”的元素中删除“类型”属性
    • 删除元素中名称为“Account”的“complexType”节点

    只允许做其中一个,要么你命名一个类型,要么你在里面匿名定义它。

    【讨论】:

    • 我无法删除类型属性,因此我删除了 complexType 节点,但我在序列节点处收到错误为“s4s-elt-must-match.1:帐户的内容”必须匹配(注释?, (simpleType | complexType)?, (unique | key | keyref)*))。发现问题开始于:sequence。
    • 如果你想定义你在Account里面得到的这种类型的内部结构,你需要“complexType”-Node及其内部,删除属性有什么问题?如果您想要的类型很简单(如“xs:string”),则“type”-Attribute 只是一种选择。我认为您需要删除该属性。
    猜你喜欢
    • 2014-01-29
    • 2021-09-22
    • 2011-03-29
    • 2018-10-24
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2014-03-27
    相关资源
    最近更新 更多