2012-02-14 22 views
9

2つのスキーマファイルがあります。 Eclipseのスキーマ内のコードを実行するが検出されたが、瓶のスキーマファイルからコードを実行するときには、jarファイル内のXSDスキーマの参照

を見つけていない場合は、ここでのコード

SAXParserFactory factory = SAXParserFactory.newInstance(); 
     factory.setNamespaceAware(true); 
     factory.setValidating(false); 

     SchemaFactory schemaFactory = SchemaFactory 
       .newInstance("http://www.w3.org/2001/XMLSchema"); 
     try { 
      factory.setSchema(schemaFactory.newSchema(new Source[] { 
        new StreamSource(getClass().getResource("Liso.xsd") 
          .getFile()), 
        new StreamSource(getClass().getResource("LisoXml.xsd") 
          .getFile()) })); 
       this.saxParser = factory.newSAXParser(); 
     } catch (SAXException se) { 
      System.out.println("SCHEMA : " + se.getMessage()); // problem in the XSD itself 
     } 

、ここでは、私が

SCHEMA : schema_reference.4: Failed to read schema document 'file:/C:/Tools/lib/LisoTools.jar!/com/xerox/liso/xml/Liso.xsd', because 1) could not find the do 
cument; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 

を取得エラーですありがとう

+0

私は2年前に同様の問題があったことを覚えています:http://stackoverflow.com/questions/2065868/need-help-with-strange-classgetresource-issue - 'getRessource()'はjava 1.4.2で動作しましたしかし、Java 1.6では... –

+0

jarに '/ com/xerox/liso/xml/Liso.xsd'が含まれていて、xsdのように見えることを確認してください:) – rogerdpack

答えて

9

LisoXml.xsdをインポートしている場合は、Liso.xsdをスキーマファクトリに定義するだけで十分です以下に示すように。 APIは読み込み/インクルードされたスキーマをロードするのに十分スマートです。

SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema") 
Schema compiledSchema = schemaFactory.newSchema(getClass().getClassLoader().getResource("Liso.xsd")) 

これは、1.5と1.6の両方で機能することを確認しました。 1.6の場合、DOMを使用している場合はthis issueにも当てはまるかもしれません。

+0

上記のリンクはどちらも死んでいます。 :-( – Bowi

関連する問題