-
semantic validation in JAXB (3 messages)
- Posted by: Dmitry Beransky
- Posted on: October 06 2006 11:27 EDT
Hi, When a user imports an xml file into our application, I need to be able to detect errors and report them and their locations in the document. The import process is done via JAXB. I know how to validate against the schema and to get error info back, but how do I catch errors that can't be constrained by a schema, like domain level (semantic) errors? Example 1: I'm parsing an xml document in which some elements contain values that are foreign keys into data stored in a database. When the document is being parsed, I want to make sure that records with those keys exist in a database. If they don't, I want to the unmarshaller to generate an error containing location info (line+position) of where this invalid value was found in the xml document. Any hints on how to implement this? Example 2: Some data being imported is in a key/value format. I need to make sure that these key/value combinations are unique within the document. E.g. 1 title 1 1 title 1 1 title 2 Parsing of the third object should raise an exception because there is already an object with id=1 associated with a different title (notice that object 2 is valid). And again, I want to be able to catch these errors during unmarshalling so that I could report their document locations. thanks dmitryThreaded Messages (3)
- Re: semantic validation in JAXB by arijit dey on October 09 2006 04:04 EDT
- Take a layered approach instead by Anthony Coates on October 15 2006 05:01 EDT
- Take a layered approach instead by Onkar Vaidya on April 12 2012 04:17 EDT
- Take a layered approach instead by Anthony Coates on October 15 2006 05:01 EDT
-
Re: semantic validation in JAXB[ Go to top ]
- Posted by: arijit dey
- Posted on: October 09 2006 04:04 EDT
- in response to Dmitry Beransky
Well! Though I don't have much knowledge about JAXB, still consider the following: If you want to validate the data integrity like your object identity, you can perse the XML file with a sax parser, and register a ErrorHandler which will output the errors. cheers, http://www.javaicillusion.blogspot.com/ -
Take a layered approach instead[ Go to top ]
- Posted by: Anthony Coates
- Posted on: October 15 2006 05:01 EDT
- in response to arijit dey
I recommend that you take a layered approach to the validation. The first layer consists of the Schema rules that JAXB checks. The second layer are other business rules that are coded in Java (either directly or using a rules engine). There is no need to do all of the validation at unmarshalling time. Cheers, Tony. -
Take a layered approach instead[ Go to top ]
- Posted by: Onkar Vaidya
- Posted on: April 12 2012 04:17 EDT
- in response to Anthony Coates
Even I have a similar situation to handle. I will be taking layered approach. But consider a scenario where I just want to validate if the data in the section, say <organization></organization> in the beginning of incoming file contains valid data. The xml file coming in will be huge and I don't want invest in reading it. Infact in some scenarios, we will have to store it in DB as CLOB, for offline processing. If the data in <organization>someuniqueidentifier</organization> section is not valid or is not found in my DB, I just want to discard the whole file returning a meaningful error to user. Any thoughts about this.