[EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] wrote:Thanks. The code is very similar to mine. Have you tried to parse an instance document referencing a schema other than those you precompile?]Yes i did try and it works fine .In my case, unless my XMLEntityResolver throws the XNIException instead of returning null, the refernced schema appears to be loaded, despite theIf i am not wrong what locked(lockPool) does is ,it prevents any new grammar being added to the cache. You should still be able to load and validate other schema and xml files.Hmm... The relevant part from the FAQ reads: "The "active" approach: Preload a grammar pool implementation with all the grammars you'll need, then lock it so that no new grammars will be added. Then registering this on the configuration will allow validators to make use of this set; registering a do-nothing EntityResolver will allow the application to deny validators from using any but the "approved" grammar set." Note that the "deny validation". So, if you parse an XML document referencing the schema NOT in the preloaded set, and it is quietly parsed, I would not consider it to be working fine. I would expect it that the velidation denial would manifest itself somehow (exception?). Don't you agree?
what i have observed is that if the xml file has the same namespace as the pre parsed schema then xml is validated against the
preparsed schema even though the xml file has a reference to a updated schema(xsd file),errors are thrown here(see below) , . But if the namespace specified in the xml file does not match with any in the cache, then the schema referred in the xml file is loaded and validated..
[Error] BookStore.xml:7:81: cvc-complex-type.3.2.2: Attribute 'Category' is not allowed to appear in element 'Book'.
[Error] BookStore.xml:7:81: cvc-complex-type.3.2.2: Attribute 'InStock' is not allowed to appear in element 'Book'.
[Error] BookStore.xml:7:81: cvc-complex-type.3.2.2: Attribute 'Reviewer' is not allowed to appear in element 'Book'.
[Error] BookStore.xml:14:85: cvc-complex-type.3.2.2: Attribute 'Category' is not allowed to appear in element 'Book'.
[Error] BookStore.xml:14:85: cvc-complex-type.3.2.2: Attribute 'InStock' is not allowed to appear in element 'Book'.
[Error] BookStore.xml:14:85: cvc-complex-type.3.2.2: Attribute 'Reviewer' is not allowed to appear in element 'Book'.
[Error] BookStore.xml:21:71: cvc-complex-type.3.2.2: Attribute 'Category' is not allowed to appear in element 'Book'.
[Error] BookStore.xml:21:71: cvc-complex-type.3.2.2: Attribute 'Reviewer' is not allowed to appear in element 'Book'.
May be some one can throw more light on this.
Regards
venu
Regards, -aRegards venugrammar pool being locked! I know it is loaded because I changed the instance document to be incorrect WRT its schema, and the parser threw the exception. -aHi , This may not solve your problem or answer your questions , but attached is a small program which i was working on , see if it is of any help. Regards venu [EMAIL PROTECTED] wrote:Hi, Perhaps this issue has been discussed on the list but the archives aren't available, so I have to post. Here goes... I am trying to use what is called 'active' schema caching, as demonstrated by the XMLGrammarBuilder example, except, I want to use DOMParser and use the DOM of the XML instances that are successfully validated. This the code I'm using SymbolTable symtab = new SymbolTable(); XMLGrammarPreparser preparser = new XMLGrammarPreparser(symtab); XMLGrammarPoolImpl pool = new XMLGrammarPoolImpl(); preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null); preparser.setProperty(GRAMMAR_POOL, pool); preparser.setFeature(NAMESPACES_FEATURE_ID, true); preparser.setFeature(VALIDATION_FEATURE_ID, true); preparser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true); preparser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true); preparser.setErrorHandler(this); System.out.println("Pre-compiling Schema from file " + xsd); Grammar g = preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, xsd, null)); pool.lockPool(); XMLParserConfiguration parsercfg = new StandardParserConfiguration(symtab, pool); parsercfg.setFeature(NAMESPACES_FEATURE_ID, true); parsercfg.setFeature(VALIDATION_FEATURE_ID, true); parsercfg.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true); parsercfg.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true); parsercfg.setEntityResolver(new XMLEntityResolver() { public XMLInputSource resolveEntity(XMLResourceIdentifier id) throws XNIException { System.out.println("Resolving resource: " + id.getLiteralSystemId()); throw new XNIException("Not resolving entity..."); //return null; } }); First question is about the XMLEntityResolver. The FAQ instructs to register a "do-nothing" EntityResolver. What does it mean? If I simply return null (do nothing?) the XML instance document that should fail validation quietly validates. Does it mean I should throw exception, as I do? That seems to work but is it "do-nothing"? More importantly, since not only need to validate XML but also get DOMs of the valid ones, I followed the FAQ again and registered the DOMParser: parser = new DOMParser(parsercfg); parsercfg.setDocumentHandler(parser); .... // f is File XMLInputSource xis = new XMLInputSource(null, f.getName(), null); System.out.println("Parsing instance XML in file " + f.getName() + " " + xis.getSystemId()); parsercfg.parse(xis); But doe not work at all! I get a NullPointerException and the XMLEntityResolver isn't called at all: Pre-compiling Schema from file 2.xsd Parsing instance XML in file 2.xml 2.xml java.lang.NullPointerException at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.startDocument(Unknown Source) at org.apache.xerces.impl.XMLNamespaceBinder.startDocument(Unknown Source) at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source) at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source) at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source) at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source) at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source) at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) [java] at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) at gov.treas.fms.sps.utils.SchemaVerifier.parse(SchemaVerifier.java:189) at gov.treas.fms.sps.utils.SchemaVerifier.parse(SchemaVerifier.java:199) ] at gov.treas.fms.sps.utils.SchemaVerifier.parse(SchemaVerifier.java:207) at gov.treas.fms.sps.utils.SchemaVerifier.main(SchemaVerifier.java:337) I tried to test the entity resolver of the DOMParser but it isn't called either: parser.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String pubid, String sysid) throws SAXException, IOException { System.out.println("DOM parser entity resolver: pub id " + pubid + ", sysid: " + sysid); return null; } }); So, can somebody explain me what am I doing something wrong? And what should I be doing to get what I want. Almost forgot, I'm using Xerces 2.2.1 and changing parser with my client is very-very-very difficult - government agency. Please. lend a helping hand. TIA, Regards, -a --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
