You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Murphy, Ed" <Ed...@aspentech.com> on 2005/03/02 23:54:26 UTC

Validate and continue after errors?

Hi,

I'm using the DOMParser with validation and I would like to be able to
validate the XML that I'm sucking in and parse what I can up to wherever an
error might occur. Currently, the document reference is coming back null. Is
this possible?

I'm porting & enhancing some code so I'm not totally clear on what all the
settings below are doing and the various documentation I've scrounged
(sun.com, apache.org, etc.) haven't answered my question. All comments
welcome.

Regards,
Ed

Some technical stuff...

String xmlDocument = "some_xml_file.xml";

DOMParser parser = new DOMParser(mySymbolTable, myGrammarPool)
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-che
cking", true);
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
parser.parse(xmlDocument);
Document document = parser.getDocument();

This e-mail and any attachments are intended only for use by the
addressee(s) named herein and may contain legally privileged and/or
confidential information. If you are not the intended recipient of this
e-mail, you are hereby notified any dissemination, distribution or copying
of this email, and any attachments thereto, is strictly prohibited. If you
receive this email in error please immediately notify the sender and
permanently delete the original copy and any copy of any e-mail, and any
printout thereof.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Validate and continue after errors?

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Ed,

That could happen if the parser threw an exception from parse before the 
Document node is created, for instance from an IOException thrown from an 
unsuccessful attempt to open the URL you specified. I don't see a 
try/catch block in your code snippet. Is the parser returning normally?

"Murphy, Ed" <Ed...@aspentech.com> wrote on 03/02/2005 05:54:26 PM:

> Hi,
> 
> I'm using the DOMParser with validation and I would like to be able to
> validate the XML that I'm sucking in and parse what I can up to wherever 
an
> error might occur. Currently, the document reference is coming back 
null. Is
> this possible?
> 
> I'm porting & enhancing some code so I'm not totally clear on what all 
the
> settings below are doing and the various documentation I've scrounged
> (sun.com, apache.org, etc.) haven't answered my question. All comments
> welcome.
> 
> Regards,
> Ed
> 
> Some technical stuff...
> 
> String xmlDocument = "some_xml_file.xml";
> 
> DOMParser parser = new DOMParser(mySymbolTable, myGrammarPool)
> parser.setFeature("http://xml.org/sax/features/namespaces", true);
> parser.setFeature("http://xml.org/sax/features/validation", true);
> parser.setFeature("http://apache.org/xml/features/validation/schema", 
true);
> 
parser.setFeature("http://apache.org/xml/features/validation/schema-full-che
> cking", true);
> 
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
> "http://www.w3.org/2001/XMLSchema");
> parser.parse(xmlDocument);
> Document document = parser.getDocument();
> 
> This e-mail and any attachments are intended only for use by the
> addressee(s) named herein and may contain legally privileged and/or
> confidential information. If you are not the intended recipient of this
> e-mail, you are hereby notified any dissemination, distribution or 
copying
> of this email, and any attachments thereto, is strictly prohibited. If 
you
> receive this email in error please immediately notify the sender and
> permanently delete the original copy and any copy of any e-mail, and any
> printout thereof.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org