My mistake ! It does not work (I forgot to remove the xmlns attribute of the root element)...
According to the following stack trace, it appears that validation against schema is performed before entering in the filter startElement method... org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ProvisioningOrders'. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRoot ElementHook(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatc her.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at org.xml.sax.helpers.XMLFilterImpl.parse(Unknown Source) Any ideas ? -----Original Message----- From: Vila Christophe Sent: mardi 24 avril 2007 15:36 To: 'Michael Glavassevich'; j-users@xerces.apache.org Subject: RE: Forcing validation without changing XML file Very good idea ! I have just tested it and it works well. Thank you ! -----Original Message----- From: Michael Glavassevich [mailto:[EMAIL PROTECTED] Sent: lundi 23 avril 2007 20:42 To: j-users@xerces.apache.org Cc: Vila Christophe Subject: Re: Forcing validation without changing XML file You could try writing a filter which sits in between the parser and the validator that modifies the namespace URIs passed through startElement() and endElement(). Take a look at XMLFilter [1] and XMLFilterImpl [2]. Thanks. [1] http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/XMLFilter.html [2] http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/helpers/XMLFilte rImpl.html Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED] "Vila Christophe" <[EMAIL PROTECTED]> wrote on 04/23/2007 02:03:03 PM: > Hi all, > > I have to write a module that parses very big XML files (>10MB) having > always the same structure. I have written a schema and would like to > validate these XML files with it... But of course, the XML files do > not declare any schema (the root element is <order> instead of <order > xmlns="mySchemaName" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="mySchemaName mySchemeURI">). > > I tried the validation API of JAXP (see the following piece of code), > but it only works if I declare at least the schema name in the XML > file (that is to say <tag xmlns="mySchemaName">) > > SchemaFactory schemaFactory = > SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); > Schema schema = schemaFactory.newSchema(new StreamSource(new > File("myschema.xsd"))); schema.newValidator().validate(new > StreamSource(new File("big.xml"))); > > I also tried ValidatorHandler, but I don't know how to add the xmlns > attribute when I am parsing the root element. > > So, is there a way to : > - force the validation against my schema without modifying the XML > files (no declaration of scheme name and location) > - validate and parse at the same time (I don't want to read the XML > files twice) > - use only SAX way (because of the XML file size) > > Thanks ! > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED]
smime.p7s
Description: S/MIME cryptographic signature