Hi Troy,
You've got two ways to handle this type of content directly in JiBX,
depending on whether the content uses what I'll call a "definite
structure" or not - but neither approach would work with the class
structure you've suggested, for that you would need a custom
marshaller/unmarshaller.
If the content has a definite structure, where you have character data
content components separated by particular elements, then you can use a
regular binding which reflects that structure. So if you know that you
always expect to have three text components separated by <br/> elements
you could build that into the binding, using a structure of this form:
<structure name="p" ...>
<value style="text" field="text1"/>
<structure name="br"/>
<value style="text" field="text2"/>
<structure name="br"/>
<value style="text" field="text3"/>
</structure>
The other alternative is to use a DOM marshaller/unmarshaller for either
the <p> element as a whole (org.jibx.extras.DomElementMapper), or for
the content inside the <p> element (org.jibx.extras.DomListMapper). This
lets you work with unstructured mixed content. From your description,
that's probably what you want - but it just gives you the data as a DOM.
To work with the class structure you've suggested you'd need to write a
custom marshaller/unmarshaller for the Paragraph component. The
unmarshalling side would just need to loop through the content, adding a
Text child for any non-whitespace text strings it found and a Break
child anytime it saw a <br/> element. When it found a nested <p> start
tag it'd just need to create a new Paragraph component and cast it to
IUnmarshallable to call the unmarshal() method, effectively invoking
itself recursively, then add that component to the list. The marshaller
just does the output equivalent.
Hopefully that will get you going.
- Dennis
Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117
Troy Kinsella wrote:
> Hi,
> I'm curious if JiBX could handle the following scenario, with or without
> custom un/marshallers.
>
> XML:
>
> <p>
> Some text
> <br/>
> Some more text
> <br/>
> Yet more text in any arbitrary order
> <p>
>
> Java:
>
> abstract class Content {}
>
> abstract class ContentContainer extends Content {
> List<Content> content;
> }
>
> class Paragraph /* <p> */ extends ContentContainer {}
>
> class Break /* <br> */ extends Content {}
>
> class Text /* plain text */ extends Content {
> String text;
> }
>
> So, specifically, I need to be able to handle a mix of child elements and
> character data defined in an arbitrary order. If custom un/marshallers are
> required, what might they look like? If this doesn't seem attainable, is
> there perhaps a better object model that could represent this structure?
>
> Thanks,
> Troy
>
>
>
> *Troy Kinsella*
> Software Developer
> Wmode Inc.
> [EMAIL PROTECTED]
> m: 403.869.7882
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users