This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Extracting path of the element during xsd validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Extracting path of the element during xsd validation" Watch "Extracting path of the element during xsd validation" New topic
Author

Extracting path of the element during xsd validation

Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

Hi,

I am using a errorHandler to handle the errors which occur during parsing.

Further i use XSD validation.

The requirement is to find the entire path of the element at which the xsd validation has failed.

At present the parser gives an error like
Invalid text '' in element: 'date_of_birth'


However if the date_of_birth element was found under two parents the end user would get confused.

Therefore i need a way to specify under which element does the date_of_birth tag come under.

Example client/date_of_birth or beneficiary/date_of_birth.

Thanks
Sudarshan
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You don't say what kind of exception this is. If it is a SAXParseException then you have getColumnNumber() and getLineNumber() methods.

You might also give the users some tool which helps them to create valid documents, instead of making them do the enter, run, fix errors cycle.
Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

Hi,

Yes i am catching the saxEcxception did run through the methods you mentioned but this is not of much use to our end client.

Actually the requirement is such that the client creates an xml through a set of forms.

We recieve this xml through a web service, process it & send back a response xml.

The response xml could specify the errors found in the request xml/subsequent business processing. Which the client software will reverse map to the fields in the form.

Now this requires us to able to uniquely identify a tag in case of a failure during the xsd validation.

I was thinking the XPath of the element would help us achieve this however cant find a way to extract the xpath of an element which has failed in the xsd validation process.

I believe that if each element had a id attribute which can help uniquely identify it then that would also serve the purpose.

But again how do i get hold of the id attribute of the element which has cause the xsd validation to fail.

Would like to add that i am using oracle's xmlparserv2 to perform the parsing and validations.


Thanks
Sudarshan
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, basically the purpose of validation is to determine whether the document is valid. That's all. It isn't like a compiler which tries to identify all errors, it just says "yes" or "no" to the question of whether the document is valid.

As I said, if your users are having problems creating valid documents, it would be better to provide them with tools that make it easier for them.
Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

Well i cant do that at present.
The validator does tell which element has caused the validation to fail.
So i was guessing we could get a few more details out of it ?

Thanks
Sudarshan
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Extracting path of the element during xsd validation
 
Similar Threads
Filter being called for Struts' forwarded JSP
javax.xml.validation doubt!
Building conditional xsd schemas
JIBX - XSD validation ?
Validating xml against xsd using dom