XML验证错误:期待已存在的标记

时间:2017-12-14 16:24:56

标签: c# xml xsd xsd-validation xml-validation

我正在开发一个XML通信工具。我的第一步是验证我正在接受的de xml。 通信适用于V2G,因此xsd位于Web上。 我下载了模式,使用了一个免费的网络验证器来检查消息,但是我得到了一个错误,我无法理解(我是xml的新手)。

架构如下:

<!-- This XML document originates from the ISO/IEC 15118-2 standard which can be obtained from ISO at http://www.iso.org/iso/catalogue_detail.htm?csnumber=55366 -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="urn:iso:15118:2:2010:AppProtocol"
    targetNamespace="urn:iso:15118:2:2010:AppProtocol">
    <xs:element name="supportedAppProtocolReq">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="AppProtocol" type="AppProtocolType" maxOccurs="20"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="supportedAppProtocolRes">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="ResponseCode" type="responseCodeType"/>
                <xs:element name="SchemaID" type="idType" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="AppProtocolType">
        <xs:sequence>
            <xs:element name="ProtocolNamespace" type="protocolNamespaceType"/>
            <xs:element name="VersionNumberMajor" type="xs:unsignedInt"/>
            <xs:element name="VersionNumberMinor" type="xs:unsignedInt"/>
            <xs:element name="SchemaID" type="idType"/>
            <xs:element name="Priority" type="priorityType"/>
        </xs:sequence>
    </xs:complexType>
    <xs:simpleType name="idType">
        <xs:restriction base="xs:unsignedByte"/>
    </xs:simpleType>
    <xs:simpleType name="protocolNameType">
        <xs:restriction base="xs:string">
            <xs:maxLength value="30"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="protocolNamespaceType">
        <xs:restriction base="xs:anyURI">
            <xs:maxLength value="100"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="priorityType">
        <xs:restriction base="xs:unsignedByte">
            <xs:minInclusive value="1"/>
            <xs:maxInclusive value="20"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="responseCodeType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="OK_SuccessfulNegotiation"/>
            <xs:enumeration value="OK_SuccessfulNegotiationWithMinorDeviation"/>
            <xs:enumeration value="Failed_NoNegotiation"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

消息是:

<?xml version="1.0" encoding="UTF-8"?>
<supportedAppProtocolReq xmlns="urn:iso:15118:2:2010:AppProtocol" xmlns:xsi="urn:iso:15118:2:2010:AppProtocol">
    <AppProtocol>
        <ProtocolNamespace>urn:din:70121:2012:MsgDef</ProtocolNamespace>
        <VersionNumberMajor>2</VersionNumberMajor>
        <VersionNumberMinor>1</VersionNumberMinor>
        <SchemaID>0</SchemaID>
        <Priority>1</Priority>
    </AppProtocol>
</supportedAppProtocolReq>

我得到的错误是:

  

错误 - 第3行,第14行:org.xml.sax.SAXParseException; lineNumber:3;   columnNumber:14; cvc-complex-type.2.4.a:找到无效的内容   从元素&#39; AppProtocol&#39;开始。其中一个{AppProtocol}&#39;是   预期

因此,据我所知,无效标记与要求的标记相同。 当然是一件简单的事情,但这让我疯狂。

0 个答案:

没有答案
相关问题