2013-02-20 30 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