2012-02-14 13 views
9

Biri diğerinden içe aktarılan iki şema dosyasına sahibim. Eclipse şemalar kod bulunur yürütme ancak kavanoz şema dosyalarından kod yürütülürken bulunmayan zaman burada Kavanoz dosyası içindeki bir XSD şemasına başvurma

kodu

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 
     } 

ve burada hata ben

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

olsun edilir Teşekkürler

+0

İki yıl önce benzer bir sorun yaşadığımı hatırlıyorum: http://stackoverflow.com/questions/2065868/need-help-with-strange-classgetresource-issue - 'getRessource()' java 1.4.2 ile çalıştı java ile değil 1.6 ... –

+0

Kavanozun/x/xerox/liso/xml/Liso.xsd' içermesi gerektiğini doğrulayın ve xsd gibi de görünüyor :) – rogerdpack

cevap

9

Liso.xsdLisoXml.xsd içeriyorsa, o zaman şema fabrikaya Liso.xsd tanımlamak için yeterlidir Aşağıda gösterildiği gibi. Api, içe aktarılan/dahil edilen şemaları yükleyecek kadar akıllıdır.

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

Bu işlemin 1.5 ve 1.6'da çalıştığını doğruladım. 1,6'da DOM kullanıyorsa this issue'a da girebilirsiniz.

+0

Yukarıdaki her iki bağlantı da ölü. :-( – Bowi