470,833 Members | 1,352 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

SOS:JAXP1.3 how to capture parent tag details in DOM-schemaValidation


OBJECTIVE---
I need to carry out validation for my XML file against a schema. My XML
contains Multiple record data each having multiple columns in it.
I want to carry out following
1 - validate XML against schema
2- delete the invalid Records from the DOM schema of the XML file
validated
3- get error message generated by Validator for failures
4- get column tag names and data where attributes defines them as
unique for reporting
5 - use the DOM object to do other business operations

#####################
PROBLEM
6--- I am able to carry out 1, 3, and 5 as well
7--- am unable to get solution for 4 - NEED HELP FOR THIS
8--- want to know whether for step 2 there is a better way to delete
the invalid records during validation itself for any validation failure
in its child tag? - NEED HELP FOR THIS

#####################
CODE approach followed SO FAR I S based on
http://java.sun.com/developer/techni...s/xml/jaxp1-3/
which allows DOM to be validated against schema
---
FOR sample xml file
<data>
<record rownum='1'>
<columnA isUNique="Y">data1</columnA>
<columnB>data2</columnB>
</record>
<record rownum='2'>
<columnA isUNique="Y">data3</columnA>
<columnB>data4</columnB>
</record>
<record rownum='3'>
......
</record>
</data>

//SchemaFactory used to compile schema and get a Schema object:
// Load Schema
String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
SchemaFactory factory = SchemaFactory.newInstance(language);
factory.setErrorHandler(new MySchemaErrorHandler());
//factory.setResourceResolver( new MyLSResourceResolver());
StreamSource ss = new StreamSource(new File("mySchema.xsd")));
Schema schema = factory.newSchema(ss);

// Load XML
File xmlFile = new File("data.xml");
DocumentBuilder parser =
DocumentBuilderFactory.newInstance().newDocumentBu ilder();
document = parser.parse(xmlFile);

// Validate

.......
Validator validator = schema.newValidator();
validator.setErrorHandler( new ErrorHandlerImpl());
DOMResult result = new DOMResult();
validator.validate(new DOMSource(document), result);
/*
//validator.validate(new StreamSource(<XML Document>));
used alternative for validator to validate the instance document or DOM
object in memory, with the augmented result sent to DOMResult.
*/
#####################
Thanks to all in advance

Apr 3 '06 #1
0 906

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by mich | last post: by
1 post views Thread by Chris Cranford | last post: by
reply views Thread by Giovane Calabrese | last post: by
29 posts views Thread by Patrick | last post: by
4 posts views Thread by SOS | last post: by
8 posts views Thread by Greg Peck | last post: by
2 posts views Thread by deejayquai | last post: by
1 post views Thread by David Douglass | last post: by
11 posts views Thread by aljaber | last post: by
12 posts views Thread by Charlie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.