users@jaxb.java.net

Validating XML against Schema Element

From: William M. Saxton <saxton_at_gmail.com>
Date: Tue, 25 Sep 2007 10:25:15 -0400

This may be more of an XML/XSD question, but since I'm using JAXB...

...is there a way to make sure an XML string matches a schema element,
and is not just valid against the whole schema.

For example, in my schema I have two elements <foo /> and <bar />. An
element of either type will validate against the schema. But, if I
have a method saveFoo(xmlString) which takes this string, how can I
ensure that xmlString is an element "foo" and not "bar"?

The not very imaginative approach would be to unmarshall it into an
object to see what type it is...that is a lot of overhead. Since I'm
saving it into the database, all I need is the XML in the string
form...