There is a particular XML blob in our SOAP messages - the structure of which is defined at runtime. I have to write logic to validate the structure and values of this blob - currently it is just mapped into a name/string value pair in a list. I have a class that has a list of elements which define what the structure and values should be, including min/max occurances and so on.

So, I was thinking of generating an XSD on the fly from the class which defines the structure and other contraints, then using that XSD to validate the XML of the blob. We use Castor (XML) and Xerces, and I was wondering which would be better to use to perform this validation.

I don't necessarily want to generate classes usingthe Schema compiler of Castor just to validate the XML as the name/string value list is working well for us with regards to using the arbitrary info from that XML (I use it in combination with the class which defines the structure to generate a GUI on the fly which lets the user enter/edit the values).

For now, I just want to validate on the server backend that the XML the client sends us matches the Schema as defined in the class which has the list of elements (and their types and contraints).

I found this online:

http://www.javaworld.com/javaworld/jw-12-2001/jw-1228-jaxb-p2.html

but it assumes that I would want to compile the Schema using Castor Schema compiler. And this:

http://www.onjava.com/pub/a/onjava/2004/09/15/schema-validation.html

which also makes assumptions about Xerces (external static XSD file)

What I am thinking I need is something that I can create/set, that holds a Schema definition (optionally writing it out to a file would be okay) that can be fed into a class (supposedly a parser), that will give me meaningful feedback on whether the XML is valid according to the Schema.

Any ideas/suggestions? Examples?

TIA



Reply via email to