元素'element'中'name'的属性值无效

时间:2015-02-12 11:55:35

标签: xml xsd schema

我有一个XML文档如下:

    <?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创建了一个模式,如下所示:

<?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时,我收到一条错误消息:

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”前缀的来源。

1 个答案:

答案 0 :(得分:4)

欢迎使用SO ...您的示例和XSD会产生误导,只是因为没有显示cbe的属性名称:CommonBaseEvent值。

话虽如此,错误确实告诉你问题是什么。您需要查找它,并了解有关NCName的更多信息。

这是一个复制品:

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'名称'   attribute无效 - 值'cbe:CommonBaseEvents'无效   根据其数据类型“http://www.w3.org/2001/XMLSchema:NCName” -   ':'字符,十六进制值0x3A,不能包含在a中   名称。

     

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

这里更好地解释了 cvc-datatype-valid.1.2.1 (基本上,:无效)。

NCName描述为here