2

(関連していないかもしれませんが、今日、私は原因を取得しました: java.io.UnsupportedEncodingException: UTF_8Oxygen XMLエディターと同じです)

エラーは次のとおりです。

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>.

これのコードの 3 行目から:

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

最初に行ったのは、パスをコピーしてテストし、正しいファイルを指していることを確認することでした。やった。

2 つ目は、Java がファイルを読み取れるかどうかを確認することで、.canRead(); を使用して確認しました。

3 番目に、ルート ノードのスキーマ内をチェックします。

<?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:schemaでしたが、このエラーが発生したため切り替えます。最も奇妙な部分は、コーディングしたときにエラーが発生しなかったことです (1 週間前)。

4

1 に答える 1

4

もちろんUTF_8、それは正しくありません。UTF-8

encodingここのXML 宣言に有効な属性値の説明がありますhttp://www.w3.org/TR/REC-xml/#NT-EncodingDecl

実際には、Java XML パーサーencodingは Java がサポートするすべてをサポートし、エイリアスも許可します。たとえば、UTF8 も適切ですが、UTF_8 は許可されません。

于 2013-02-20T07:58:54.180 に答える