aspose file tools*
The moose likes XML and Related Technologies and the fly likes data validation using XSD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "data validation using XSD" Watch "data validation using XSD" New topic
Author

data validation using XSD

Karan Jain
Ranch Hand

Joined: May 30, 2007
Posts: 82
Hi,
I need to parse a fixed length text file and then do the data validation on it. File can contain 100+ records.
Data validation for each record will typically have:
1) Numeric check, min/max value check, decimal precision check etc.
2) Date check
3) currency code is same in all the amount fields in the record.
4) couple of fields will be validated from the database too...

File level validation:
1)sequence number are in order in the file for each record.
2)seq of record should be header, data --- data , trailer... then again header, data... data, trailer and then finally end.

Whenever there is an error in a field for a record i need to store the error message for the field... and then finally display all the errors for each field in each record rendering an html page.

What can be the a good approach to attack this problem?
I came across an article but very old.
http://www.javaworld.com/javaworld/jw-09-2000/jw-0908-validation.html
http://www.javaworld.com/javaworld/jw-10-2000/jw-1013-validation2.html
http://www.javaworld.com/javaworld/jw-11-2000/jw-1110-validation3.html
http://www.javaworld.com/javaworld/jw-12-2000/jw-1208-validation4.html?page=1

I am not sure whether that validation method still good. I am not allowed to use open source utilities.

Is there a way so that i create an XSD and then validate a XML and capture all the errors and not just to check whether the XML is valid or not. I need field level error capturing.

Any help is appreciated.

Thanks and regards,
Karan
[ July 16, 2007: Message edited by: Karan Jain ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

Most of the four validation points you have there can't be done via XML Schema, even if you did have XML as your input. So that doesn't sound like a promising approach to me.
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Paul is correct.

XML Schema is not for validating data, but XML file format, maybe a little data. Your data is not even in a XML file!!!

You probably don't want to use a hammer to sew your jacket.

Your data file is text, why do you not just write a simple text processing code to validate your data, nice and easy, since you know your text file format!

If you are starting to write your own code, you will quickly find out it is not as hard as you thought.
[ July 16, 2007: Message edited by: Roseanne Zhang ]
Karan Jain
Ranch Hand

Joined: May 30, 2007
Posts: 82
I think i asked the question in a wrong way.

Actually i want to validate the data while parsing the file. If you look at the articles what its doing is:
Storing the constraints in an XSD and reading the XSD to validate the input text. Constraints many be min-max values, allowed values, max length etc. Everything is done in Java.

I will definitely write the code but i was not eager to hard-code those type of values.

I was not sure why the author of the article is using XSD and not XML to configure those things...

Please bear with me as I am very new to these things..

Thanks and regards,
Karan
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Storing the constraints in an XSD and reading the XSD to validate the input text. Constraints many be min-max values, allowed values, max length etc. Everything is done in Java.


XSD validation has nothing to do with "Everything is done in Java." They are not the same thing. Java is a general purpose language, of course, it can do almost anything or everything, but XSD is not.

However, I think that we have discussed your "fixed length text file " enough, from XSLT to XSD. I will quit on this issue. Sorry!
[ July 16, 2007: Message edited by: Roseanne Zhang ]
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Here is a link to the previous discussion related to XSLT, just in case others are curious.

http://www.coderanch.com/t/129260/XML/Creating-XML-fixed-length-text

Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: data validation using XSD