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/XMLFilterImpl.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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to