users@jaxb.java.net

Re: XML content within an element

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 19 Feb 2003 08:18:23 -0800

Thanks for the detailed explanation.


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();
  }

where the getContent method will return the object unmarshalled from XXX
part. So your core module can just inspect the Event object and then
dispatch its content to the customer module, and the customer module can
cast it to another generated interface and take it from there.


Another thing you can do, which unfortunately requires more coding, is
to rewrite your core module as a SAX filter. If you just need to look at
the event element, this won't be so hard.

You determine the module that receives the content of the event when you
see its start tag, and then redirect the sub-tree to JAXB unmarshaller
to just unmarshal XXX part.

This is probably more efficient (both in terms of memory footprint and
turn around time) than unmarshalling everything as JAXB tree.



> <xsd:complexType name="EventEnvelope">
> <xsd:simpleContent>
> <xsd:extension base="xsd:CDATA">
> <xsd:attribute name="type" type="xsd:string"/>
> <xsd:attribute name="version" type="xsd:string"/>
> </xsd:extension>
> </xsd:simpleContent>
> </xsd:complexType>

First of all, there's no "CDATA" type and also this doesn't allow you to
write child elements inside an <event> element. This definition doesn't
look like what you want.


regards,
--
Kohsuke KAWAGUCHI                  408-276-7063 (x17063)
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com