Skip to main content

jaxp + jaxb to porcess and validate XML

3 replies [Last post]
jaxpb
Offline
Joined: 2007-11-29
Points: 0

Don't we need both the advanced constraint validation (like key/keyrefs) and Marshal/Unmarshal capability in one toolkit?

I have a situation where I do have key/keyref constraints in my W3C schema. I need a tool to validate such constraints. JAXB doesn't seem to do that but JAXP does. I also need Marshal/Unmarshal feature to process between XML/Java objects. I could use JAXB here. Isn't there one toolkit which does both? I thought this is a very common need? Looks like I am wrong!

Typically, a user would process incoming XML and store in DB. In the other direction, read from DB and generate an XML. I guess JAXB seems like a perfect fit here. But, it lacks identity constraint validation. I am curious what tools/libraries people use to get both MArshal/Unmarshal and Key/Keyref validation.

my current platform is Java 5.0.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
prunge
Offline
Joined: 2004-05-06
Points: 0

You can use the setSchema()

method on a JAXB Unmarshaller to perform validation during JAXB unmarshalling. That still leaves you with the task of getting a Schema object, which you can do using a JAXP SchemaFactory and your schema file.

jaxpb
Offline
Joined: 2007-11-29
Points: 0

But JAXB still doesn't do key/keyref constraint validation right?

Isn't using XMLBeans provides the capability of both jaxb and jaxp?

prunge
Offline
Joined: 2004-05-06
Points: 0

JAXB doesn't do key/keyref validation nor a lot of fine-grained type validation. It only does enough 'validation' so that it can unmarshal into Java objects. Other rules like length constraints are not validated at all by JAXB.

For proper validation, you'll need to use setSchema() and let JAXP do validation.