Re: flexible unmarshalling
Hello,
>
> I was wondering if JAXB is capable of unmarshalling only a specific couple
> of inner elements / attributes into a jaxb annotated (i.e. not xjc
> generated) class. For example... take the following xml.
>
> <Example>
> <elementidontcareabout>
> <innerelementistillwanttoignore>
> <thisiswhatiwant iwantthisattribute="hello">
> <somevalueilike iwantthistoo="hi">nice to meet you
> </somevalueilike>
> </thisiswhatiwant>
> </innerelementistillwanttoignore>
> </elementidontcareabout>
> </Example>
>
> I would like to unmarshall it into the following class.
>
> public class Example {
> @XmlAttribute(name = "iwantthisattribute")
> private String iwantthisattribute;
>
> @XmlAttribute(name = "iwantthistoo")
> private String iwantthistooattribute;
>
> @XmlElement(name = "somevalueilike")
> private String somevalueilike;
> }
>
> as you can see I'm only interested in unmarshalling a few inner elements
> into my class, I'm not concerned with any of the outer elements.
>
> Is this possible in a relatively simple way using jaxb? I've been able to
> do this using a castor custom mapping.xml file however as I'm in the
> process of evaluating castor vs jaxb I want to determine if the same
> capabilities are possible using jaxb.
>
> Although we're not really concerned with schema validation or generating
> code from a schema here is the schema for the defined xml above.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema ">
> <xs:element name="Example">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="elementidontcareabout">
> <xs:complexType>
> <xs:sequence>
> <xs:element
> name="innerelementistillwanttoignore">
> <xs:complexType>
> <xs:sequence>
> <xs:element
> name="thisiswhatiwant">
> <xs:complexType>
> <xs:sequence>
> <xs:element
> name="somevalueilike">
> <xs:complexType>
> <xs:attribute
> name="iwantthistoo" type="xs:string" use="required"/>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> <xs:attribute
> name="iwantthisattribute" type="xs:string" use="required"/>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
> Any help would be much appreciated!
>
> Regards,
>
> Bryan
>
>