logo       

Re: Forcing validation without changing XML file: msg#00037

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

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@xxxxxxxxxx
E-mail: mrglavas@xxxxxxxxxx

"Vila Christophe" <Christophe.VILA@xxxxxxxxxxx> 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: j-users-unsubscribe@xxxxxxxxxxxxxxxxx
> For additional commands, e-mail: j-users-help@xxxxxxxxxxxxxxxxx


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe