Without the full schemas and message, it's hard to diagnose. One thing you
could do though, since you have the schema, is to use the
javax.xml.validation.SchemaFactory API's to create a Schema object from your
xsd and then, before calling unmarshall, call the unmarshaller.setSchema(..)
method with it to turn on complete schema validation. You can also call
unmarshaller.setEventHandler with a ValidationEventHandler that prints some
information out or similar. JAXB, by default, ignores a lot of things it
doesn't understand. If you set a ValidationEventHandler and/or turn on the
schema validation, you may get some exceptions or extra information about what
it is doing that is really invalid or similar.
Dan
On Wednesday 16 March 2011 10:23:28 AM eaudet wrote:
> Here's a much more precise explanation. I have scalled down to pure JAXB to
> understand to problem.
>
> I have generated my java classes using this command:
>
> xjc -d ./src MySchema.xsd
>
>
> Everything compiles. Nice!. Here's a part of my xsd in problem:
>
> ...
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> .....
>
>
>
> Here's the generated **EN** class:
>
> ....
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "EN", propOrder = {
> "content"
> })
> @XmlSeeAlso({
> ON.class,
> PN.class,
> TN.class
> })
> public class EN {
>
> @XmlElementRefs({
> @XmlElementRef(name = "delimiter", namespace =
> "urn:hl7-org:v3", type = JAXBElement.class),
> @XmlElementRef(name = "validTime", namespace =
> "urn:hl7-org:v3", type = JAXBElement.class),
> @XmlElementRef(name = "suffix", namespace = "urn:hl7-org:v3",
> type = JAXBElement.class),
> @XmlElementRef(name = "prefix", namespace = "urn:hl7-org:v3",
> type = JAXBElement.class),
> @XmlElementRef(name = "family", namespace = "urn:hl7-org:v3",
> type = JAXBElement.class),
> @XmlElementRef(name = "given", namespace = "urn:hl7-org:v3",
> type = JAXBElement.class)
> })
> @XmlMixed
> protected List content;
> ......
>
>
>
> Here's the related XML example file in problem (fits with the above
> XSD) :
>
>
>
> ...
>
>
> Smith
> John
>
>
> ...
>
>
>
>
>
> Here's the java code doing the unmarshalling in problem:
>
>
>
>
> ...
> for (Serializable s :
> pPersonName.getValue().getContent()) {
> if (s instanceof String) {
> System.out.print((String) s);
> } else {
> String tag = ((JAXBElement)
> s).getName().getLocalPart();
> if (s instanceof EnFamily) {
> EnFamily chunk = (EnFamily)
> ((JAXBElement) s).getValue();
> System.out.print("(" + tag +
> ":");
> }
> }
> }
> ...
>
>
>
> And here's my problem: The class **EnFamily** extracted from a
> JAXBElement does not contain any values. It should contain "Smith". It
> seems it is not unmarshalling correctly.
>
> Any help appreciated!
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/How-to-get-String-values-out-of-a-JAXBElem
> ent-object-tp3424129p3782616.html Sent from the cxf-user mailing list
> archive at Nabble.com.
--
Daniel Kulp
[email protected]
http://dankulp.com/blog
Talend - http://www.talend.com