2012-02-14 18 views
9

के भीतर एक एक्सएसडी स्कीमा का संदर्भ देना मेरे पास दो स्कीमा फ़ाइलें हैं जिन्हें एक दूसरे से आयात किया जाता है। जब क्रियान्वित ग्रहण स्कीमा में कोड पाए जाते हैं, लेकिन जब जार स्कीमा फ़ाइलों से कोड को क्रियान्वित नहीं पाए जाते हैंजार फ़ाइल

यहाँ कोड

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

मुझे याद है कि मेरे पास दो साल पहले एक समान समस्या थी: http://stackoverflow.com/questions/2065868/need-help-with-strange-classgetresource-issue - 'getRessource()' जावा 1.4.2 के साथ काम किया लेकिन जावा 1.6 के साथ नहीं ... –

+0

आपको सत्यापित करें कि जार में '/ com/xerox/liso/xml/Liso.xsd' शामिल है और यह एक xsd जैसा दिखता है :) – rogerdpack

उत्तर

9

यदि Liso.xsdLisoXml.xsd आयात कर रहा है, तो यह स्कीमा फैक्ट्री में Liso.xsd को परिभाषित करने के लिए पर्याप्त है जैसा की नीचे दिखाया गया। एपीआई पर्याप्त आयातित/शामिल स्कीमा लोड जितना स्मार्ट है।

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

संबंधित मुद्दे