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

C

chetan.33

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/technicalArticles/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().newDocumentBuilder();
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top