Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Validating XML using the Xerces DOM parser

Reply
Thread Tools

Validating XML using the Xerces DOM parser

 
 
Helen
Guest
Posts: n/a
 
      03-02-2004
I have a web app that reads an XML file uploaded by a user, parses it
and adds the information inside it to a database.

To make sure that the users aren't putting invalid data into the
database, I thought the easiest way to do this would be to write an
XML schema to validate it.

I want all documents uploaded to be validated by this particular
schema. I'm only interested in processing documents that conform to
this schema. I want the parsing to fail for any other file.

I've checked my XML file and my schema by validating them using XML
Spy. XML Spy has no problems applying the schema to the xml file and
picking up any deliberate errors that I put into the file.

I'm using the Xerces DOM parser (version 2.6.2) to read the XML. When
I run the code with valid XML, it works fine, but if I include errors
in the XML file it doesn't pick them up.

DOMParser parser = new DOMParser();
parser.setFeature("http://xml.org/sax/features/namespaces", false);
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
"http://localhost:8080/assetDB/schema/assetList.xsd");
Parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
true);
parser.parse(xmlSource);
parser.setErrorHandler(this);
Document assetDoc = parser.getDocument();

What I really want to do is this:
get XML file
Validate xml file
If valid
process file
else
give helpful error messages
end if

Am I even going about this the right way?

I appreciate any help (or even pointers to good java/xml resources)

Helen
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validating XML document using Xerces-J Kevin Partin XML 1 02-13-2004 01:02 PM
Validating xml with xsd schema using xerces Yona XML 0 10-29-2003 01:04 PM
parsing XML to DOM, validating against a local DTD, using Xerces under JAXP? bugbear XML 0 08-28-2003 09:22 AM
xerces-C++:- validating an DOM Daniel Ng XML 0 08-04-2003 08:27 PM
Validating with in-memory Xml Schema using Xerces Jasmin Wason XML 0 08-01-2003 03:15 PM



Advertisments