2013-02-20 39 views
2

(不包括它可能不相關的,但今天我剛剛產生的原因:java.io.UnsupportedEncodingException: UTF_8並與氧XML編輯器相同)如何調試org.xml.sax.SAXParseException; schema_reference.4?

的錯誤是:

SEVERE: null  
org.xml.sax.SAXParseException; schema_reference.4: Failed to read schema document 'file:/fileLocation', because 1) 
could not find the document; 2) the document could not be read; 3) the root element 
of the document is not <xsd:schema>. 

從這個代碼第三行來:

File schemaFile = new File("filenName.xsd"); 
      SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 
      Schema schema = schemaFactory.newSchema(schemaFile); 

我做的第一件事就是複製路徑並測試它以確保它指向正確的文件。我做到了。

其次是檢查是否Java能夠讀取文件,並通過使用.canRead()檢查;

第三我檢查根節點的模式。

<?xml version="1.0" encoding="UTF_8"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" 
    targetNamespace="name" xmlns="name"> 
    ... 
</xsd:schema> 

它曾經是XS:模式,但我打開它,因爲我得到這個錯誤。最奇怪的部分是,當我編碼,我沒有得到任何錯誤(1周前)。

回答

4

當然UTF_8的是不正確,應該是UTF-8

有什麼有效encoding atrribute值在XML聲明這裏http://www.w3.org/TR/REC-xml/#NT-EncodingDecl

在實踐中的解釋,Java的XML解析器支持Java支持任何encoding,也允許別名,例如UTF8也不錯,但不是UTF_8。

+0

替換所有的問題,但仍然不能確定爲什麼一個小 - _使得Oxygen和Netbeans崩潰。 (現在他們不) – Juan 2013-02-20 08:57:35