2011-11-27 30 views
0

對於我的XML文件,我有驗證模式無效字節1個字節的UTF-8序列

<?xml version="1.0" encoding="UTF-8"?> 
<forum> 
    <post> 
     <description>The Day is coming </description> 
     <date> Thu, 16 Apr 2009 </date> 
     <title> cats </title> 
    </post> 

    <post> 
     <description> its raining </description> 
     <date> Tues, 12 Apr 2010 </date> 
     <title> dog </title> 
    </post> 

    <post> 
     <description>Game over </description> 
     <date> Tues, 16 Apr 2009 </date> 
     <title> frog </title> 
    </post> 

    <post> 
     <description> Watch </description> 
     <date> wednesday, 12 Apr 2010 </date> 
     <title> hats </title> 
    </post> 
</forum> 

我的XSD文件

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs=」http://www.w3.org/2001/XMLSchema」> 
<xs:element name="forum" type="xs:forumtype"> 
    <xs:complexType name = "forumtype"> 
    <xs:sequence> 
     <xs:element name="post" type ="posttype"/> 
    </xs:sequence> 
    </xs:complexType> 
    <xs:complexType name="posttype"> 
     <xs:sequence> 
      <xs:element name="description" type="xs:string"/> 
      <xs:element name="date" type="xs:string"/> 
      <xs:element name="title" type="xs:string"/> 
      </xs:sequence> 
     </xs:complexType> 
     </xs:element> 
    </xs:schema> 

當我嘗試驗證的架構,我得到無效的字節1的1個字節的UTF-8序列。即使我將編碼設置爲「UTF-8」,爲什麼它仍然不喜歡這個?

回答

1

你應該包含更多的信息:平臺/語言,具體的錯誤信息,以便於建議的事情。 但假設錯誤消息表明UTF-8編碼存在問題,這發生在較低級別(在XML解析期間),並且與Schema驗證無關。

相反,基礎XML文檔使用的編碼方式不同於解析器被告知它應該使用的編碼方式 - 最常見的內容使用類似Latin-1(ISO-8859-1)編碼(或類似)的東西。您可以通過解析文檔來驗證這一點,並且應該會得到類似的錯誤,而不管架構如何。

所以你可能有一個破碎的文件(使用的編碼不是XML聲明所具有的);或者您使用索賠編碼錯誤的代碼。

+0

我正在使用http://tools.decisionsoft.com/schemaValidate/,它將模式與xml進行比較並驗證它們。我的模式顯然不是「格式良好」,意味着錯誤在於我的模式語法 – Jake

+0

正確的,在嘗試讀取模式定義時可能會出現分析錯誤。但是提到UTF-8的錯誤的確表明了一個低層次的問題,低於正確的形式...... – StaxMan

0

我用了一個免費的編輯器,它是默認的unicode。改變編碼固定它。

0

您發佈的XML 文本,但這個錯誤其實是在抱怨存儲在源的二進制表示。二進制源顯然不是真正的UTF-8。

相關問題