本文介紹了XML 模式驗(yàn)證錯(cuò)誤的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我的 xml 文件為
<?xml version="1.0" encoding="ISO-8859-1"?>
<Info>
<Pan>123</Pan>
<Name>qwe</Name>
<Email>qwe</Email>
<City>qwe</City>
<State>qwe</State>
<AssessmentYear>2012</AssessmentYear>
<MobileNo>1234</MobileNo>
<Income-Salary>1234</Income-Salary>
<Income-Other>1234</Income-Other>
<TotalAmount>122</TotalAmount>
<Signature>
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><Transform Algorithm="http://www.w3.org/TR/1999/REC-xslt-19991116"><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
Pan : <xsl:copy-of select="http://Pan"/>
MobileNo : <xsl:copy-of select="http://MobileNo"/>
TotalAmount : <xsl:copy-of select="http://TotalAmount"/>
</xsl:template>
</xsl:stylesheet></Transform></Transforms><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>FgbIIimTLIbd0Zpvq1zDrZse6aJg5bAE1/Q58cEkEvk=</DigestValue></Reference>
</SignedInfo>
<SignatureValue>dy4QDco5NhXResncu0tUG5ylujDn9siIQSHjuX5HxH2gs70LpsO3KDWNvDXjpgkIySYfzJ/FdC6C
trkSySWRjhObqI8cbcP5VU/nL8pP21+3CO+gF1k884aeX3felpRy0FBBMTYBknQTunWCHvpHk927
ZHGvm6Hiej7iBKr3e1k=</SignatureValue>
</Signature>
</Info>
我的這個(gè)xml文件的Schema文件如下(c1.xsd)
My Schema files for this xml file is as follows(c1.xsd)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="C:\xml\c2.xsd"/>
<xs:element name="Info">
<xs:complexType>
<xs:sequence>
<xs:element name="Pan" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Email" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="State" type="xs:string"/>
<xs:element name="AssessmentYear" type="xs:gYear"/>
<xs:element name="MobileNo" type="xs:unsignedLong"/>
<xs:element name="Income-Salary" type="xs:unsignedLong"/>
<xs:element name="Income-Other" type="xs:unsignedLong"/>
<xs:element name="TotalAmount" type="xs:unsignedLong"/>
<xs:element ref="ds:Signature"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
c2.xsd(已編輯)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2000/09/xmldsig#">
<xs:element name="Signature">
<xs:complexType>
<xs:sequence>
<xs:element name="SignedInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="CanonicalizationMethod">
<xs:complexType>
<xs:attribute name="Algorithm" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="SignatureMethod">
<xs:complexType>
<xs:attribute name="Algorithm" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="Reference">
<xs:complexType>
<xs:attribute name="URI" type="xs:string"/>
<xs:all>
<xs:element name="Transforms">
<xs:complexType>
<xs:sequence>
<xs:element name="Transform" type="xs:string">
<xs:complexType>
<xs:attribute name="Algorithm" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="DigestMethod">
<xs:complexType>
<xs:attribute name="Algorithm" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="DigestValue" type="xs:hexBinary"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="SignatureValue" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
當(dāng)我驗(yàn)證我的 xml 文件時(shí),我得到以下異常
When I validate my xml file i get the following Exception
org.xml.sax.SAXParseException; systemId: file:/C://xml//c2.xsd; lineNumber: 22;
columnNumber: 37; s4s-elt-invalid-content.1: The content of '#AnonType_Reference
SignedInfoSignature' is invalid. Element 'element' is invalid, misplaced, or oc
curs too often.
我不知道我哪里出錯(cuò)了?誰能告訴我代碼中的錯(cuò)誤到底在哪里?
編輯 1 后出錯(cuò)
org.xml.sax.SAXParseException; systemId: file:/C://xml//c2.xsd; lineNumber: 22;
columnNumber: 15; s4s-elt-invalid-content.1: The content of '#AnonType_Reference
SignedInfoSignature' is invalid. Element 'all' is invalid, misplaced, or occurs
too often.
推薦答案
在c2.xsd,第22行
At c2.xsd, line 22
<xs:complexType>
<xs:attribute name="URI" type="xs:string"/>
<xs:element name="Transforms">
xs:element
不能作為 xs:complexType
的直接子級出現(xiàn).它必須在 xs:all
、xs:choice
或 xs:sequence
內(nèi).
xs:element
cannot appear as a direct child of xs:complexType
. It must be inside xs:all
, xs:choice
or xs:sequence
.
這篇關(guān)于XML 模式驗(yàn)證錯(cuò)誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!