Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: chetan.33@-----.---
To: NULL
Date: 4/2/2006 10:29:00 PM


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



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent