users@jaxb.java.net

Re: XML content within an element

From: Marcus Walls <marcus.walls_at_ASPECTIVE.COM>
Date: Thu, 20 Feb 2003 15:19:44 -0700

Kohsuke,

Thanks for the response.

> Assuming that the "XXXX" part is defined as an wildcard, I think JAXB
> will do the right thing by default. You'll get something like:
>
> public interface Event {
> String getType();
> String getVersion();
> javax.xml.bind.Element getContent();
> }

I looked up what you meant by wildcard (I really don't know any schema)
and I now have schema that looks like the following:

  <xsd:element name="event">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:any/>
      </xsd:sequence>
      <xsd:attribute name="type" type="xsd:string"/>
      <xsd:attribute name="version" type="xsd:string"/>
    </xsd:complexType>
  </xsd:element>

which produces the interface as above. However, when I try to
unmarshall the following document:

  <event type="type" version="version">
    <hello>goodbye</hello>
  </event>

I get a NullPointerException - stack-trace included below.
This is presumably either a bug or I'm doing something silly.

Assuming this problem is fixable, and I end up with a
javax.xml.bind.Element, you mentioned that I should "cast it to
another generated interface". I'm not sure how this works!

i.e. How do I get JAXB to unmarshal the "<hello>goodbye</hello>"?
I guessed that I'd need to create a JAXBContext for the package
in which the "<hello>goodbye</hello>" objects reside, and then
pass the javax.xml.bind.Element to the unmarshaller, but there
doesn't appear to be the methods for doing this?

I guess I'm not really sure what the javax.xml.bind.Element is
really representing, and I don't see how JAXB can manipulate
any of the objects representing the <hello> element, because
it wouldn't know which package the objects resided in?

In short, I'm confused!

Regards,

Marcus



-- stack-trace mentioned above --

java.lang.NullPointerException
    at com.sun.xml.bind.validator.MSVValidator.childAsElements(MSVValidator.java:249)
    at com.aspective.common.test.event.xml.impl.EventTypeImpl.serializeElements(EventTypeImpl.java:55)
    at com.aspective.common.test.event.xml.impl.EventImpl.serializeElements(EventImpl.java:41)
    at com.sun.xml.bind.validator.MSVValidator._validate(MSVValidator.java:88)
    at com.sun.xml.bind.validator.MSVValidator.validate(MSVValidator.java:69)
    at com.sun.xml.bind.validator.ValidationContext.validate(ValidationContext.java:78)
    at com.sun.xml.bind.validator.ValidatorImpl.validate(ValidatorImpl.java:99)
    at com.sun.xml.bind.validator.ValidatorImpl.validateRoot(ValidatorImpl.java:80)