users@jaxb.java.net

Re: XML content within an element

From: Marcus Walls <marcus.walls_at_ASPECTIVE.COM>
Date: Wed, 19 Feb 2003 02:48:47 -0700

My apologies, I'm having difficulty articulating this problem.

> Is it more like
>
> public interface Event {
> String getType();
> String getVersion();
> org.w3.dom.Element getContent();
> }

Yes, I think this may be what I'm looking for.

However, just in case I'm asking for the wrong thing, let me
explain my problem!

My application is split into "core" and "customer". The core
part contains lots of "event-processing" code which works on
the Event interface I mentioned last time. The core part
dictates that the XML representation of the event looks
something like:

    <event type="type" version="1.0">
      XXXXX
    </event>

with the event element being core, and the XXXXX is defined
by the "customer" code. The XXXXX is XML.

Therefore my "core" code wants to be able to parse this piece
of XML via JAXB, validate the <event> "envelope" and then
pass the XXXXX off to a piece of "customer" code (either as
a string or as a org.w3.dom.Element) which can then use JAXB
to parse the XXXXX.

The idea is that the "customer" code doesn't need to know
that XXXXX was once embedded within an <event> and the core
code doesn't need to know about XXXXX.

Thus in my "core" code I'd like a way to be able get JAXB
to parse the XML file, but not complain that it doesn't know
anything about XXXXX. (I'm happy for it to complain if
XXXXX is not well-formed).

My only thoughts on a solution to this problem at the moment
are to use string processing to split the XML into "XXXXX"
and "<event type="type" version="1.0"></event>" and parse
them independently.

This will work I believe, but it doesn't strike me as a
*good* solution, and since I'm pretty ignorant of XML
Schema I wondered if there was a better way to do this.

e.g. in my naivety I was looking for something like:

  <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>

I hope that's made things clearer! Any suggestions
(or comments upon my approach) would be appreciated.

Thanks

Marcus