元素“element"中“name"的属性值无效 [英] Invalid attribute value for 'name' in element 'element'

查看:41
本文介绍了元素“element"中“name"的属性值无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XML 文档,如下所示:

I have an XML document as below:

    <?xml version="1.0" encoding="UTF-8"?>
<cbe:CommonBaseEvents xmlns:cbe="http://www.ibm.com/AC/commonbaseevent1_1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <cbe:CommonBaseEvent>
        <sourceComponentId component="25541"
            componentIdType="Application" location="abcxxxxx"
            locationType="Hostname" subComponent="ia" />
        <situationInformation extensionName="FeedNotification"
            creationTime="2008-02-08T12:00:00">
            <extendedDataElements name="FeedNotification"
                type="string">
                <children name="fileType" type="string">
                    <values>ACBAL</values>
                </children>
                <children name="file" type="string">
                    <values>acountandbalances/input/finalT24_ACBAL_MY0010001_200902115941323.csv</values>
                </children>
                <children name="archiveDirectory" type="string">
                    <values>accountandbalances/input/archive</values>
                </children>
            </extendedDataElements>
            <situationType category="CREATE" successDisposition="SUCCESSFUL"
                situationQualifier="FileTransfer" reasoningScope="INFO" />
        </situationInformation>
    </cbe:CommonBaseEvent>
</cbe:CommonBaseEvents>

我为此 XML 创建了一个架构,如下所示:

And i have created a schema for this XML as below:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cbe="http://www.ibm.com/AC/commonbaseevent1_1">
<xs:include schemaLocation="../../00.GEN.Generic/INTF/COMMON_RULES.xsd" />

    <xs:complexType name="sourceComponentIdType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="component" type="xs:string"/>
                <xs:attribute name="componentIdType" type="xs:string"/>
                <xs:attribute name="location" type="xs:string"/>
                <xs:attribute name="locationType" type="xs:string"/>
                <xs:attribute name="subComponent" type="xs:string"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>


    <xs:element name = "cbe:CommonBaseEvents">
        <xs:complexType>
            <xs:sequence>
                <xs:element name = "cbe:CommonBaseEvent">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="sourceComponentId" type="sourceComponentIdType" />
                            <xs:element name="situationInformation">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="extendedDataElements">
                                            <xs:complexType>
                                                <xs:sequence>
                                                    <xs:element name="children" maxOccurs="unbounded">
                                                        <xs:complexType>
                                                            <xs:sequence>
                                                                <xs:element name="values" type="xs:string" />
                                                            </xs:sequence>
                                                            <xs:attribute name="name" type="xs:string"/>
                                                            <xs:attribute name="type" type="xs:string"/>
                                                        </xs:complexType>
                                                    </xs:element>
                                                </xs:sequence>
                                                <xs:attribute name="name" type="xs:string"/>
                                                <xs:attribute name="type" type="xs:string"/>
                                            </xs:complexType>
                                        </xs:element>   
                                    </xs:sequence>
                                    <xs:attribute name="extensionName" type="xs:string"/>
                                    <xs:attribute name="creationTime" type="xs:string"/>
                                </xs:complexType>
                            </xs:element>   
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>   
            </xs:sequence>
        </xs:complexType>
    </xs:element>   

</xs:schema>

但是,在验证 XML 与 Schema 时,我收到一条错误消息:

However, while validating XML vs Schema, i get an error that says:

Error - Line 18, 44: org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 44; s4s-att-invalid-value: Invalid attribute value for 'name' in element 'element'. Recorded reason: cvc-datatype-valid.1.2.1: 'cbe:CommonBaseEvents' is not a valid value for 'NCName'.

Error - Line 18, 44: org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 44; s4s-att-must-appear: Attribute 'name' must appear in element 'element'.

Error - Line 21, 46: org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 46; s4s-att-invalid-value: Invalid attribute value for 'name' in element 'element'. Recorded reason: cvc-datatype-valid.1.2.1: 'cbe:CommonBaseEvent' is not a valid value for 'NCName'.

Error - Line 21, 46: org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 46; src-element.2.1: : One of 'ref' or 'name' must be present in a local element declaration.

请帮助我理解我在这里做错了什么,我确定这与不理解cbe"前缀来自哪里的模式有关.

Please help me understand what am i doing wrong here, i am sure its something to do with the schema not understanding where "cbe" prefix is coming from.

推荐答案

欢迎来到 SO... 您的示例和 XSD 具有误导性,即使只是因为没有显示 cbe:CommonBaseEvent 值的属性名称.

Welcome to SO... Your sample and XSD are misleading, if only because there's no attribute name showing a cbe:CommonBaseEvent value.

话虽如此,错误确实告诉您问题出在哪里.您需要查找它,并详细了解 NCName 是什么.

That being said, the error really tells you what the problem is. You need to look it up, and learn more about what NCName is.

这是一个再现:

一个 XSD:

<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="root">
        <xsd:complexType>
            <xsd:attribute name="name" type="xsd:NCName"/>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

一个 XML:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="cbe:CommonBaseEvents"/>

错误:

加载 [] 时出错,第 3 行位置 61 'name'属性无效 - 值cbe:CommonBaseEvents"无效根据其数据类型 'http://www.w3.org/2001/XMLSchema:NCName' -':' 字符,十六进制值 0x3A,不能包含在名称.

Error occurred while loading [], line 3 position 61 The 'name' attribute is invalid - The value 'cbe:CommonBaseEvents' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:NCName' - The ':' character, hexadecimal value 0x3A, cannot be included in a name.

加载 [] 时出错,第 3 行位置 90cvc-datatype-valid.1.2.1: 'cbe:CommonBaseEvents' 不是有效值对于NCName".

Error while loading [], line 3 position 90 cvc-datatype-valid.1.2.1: 'cbe:CommonBaseEvents' is not a valid value for 'NCName'.

这里的 cvc-datatype-valid.1.2.1 解释得更好(基本上,: 是无效的).

Here it was the cvc-datatype-valid.1.2.1 explained better (basically, : is invalid).

NCName 在此处描述.

NCName is described here.

这篇关于元素“element"中“name"的属性值无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆