We are using Castor-XML for marshalling/unmarshalling SOAP messages, and we are using mapping files. Almost all of our SOAP messages have a known structure - so so far so good.
However, some of our messages contain an XML structure which is somewhat arbitrary. We have been mapping this to a HashMap, but there are two problems:
1) It seems too complex - especially for me, as I have trouble getting my head wrapped around this structure in order to move the data in and out of the HashMap from a GUI (which is built on the fly to edit the data).
2) The XML may contain multiple instances of an element within a given node - for example:
<auto color="red" make="toyota" >
<notes>Notes 1: test, test, is this mike working?</notes>
<notes>Notes 2</notes>
<notes>Notes 3</notes>
<notes>Notes 4</notes>
<notes>Notes 5</notes>
<notes>Notes 6</notes>
</auto>It may also contain no or empty instances of that particular element.
I do know ahead of time something of the structure to expect, because it is defined in a class which has a list of what these elements may be (for example, boolean, string, text (a long string), a class (containing a structure of other elements), a date, etc.), but I do not know this structure until runtime, and it can change during runtime - it can even change between the time I unmarshall it and marshall it back out (the user may add new elements, or remove elements).
A given element may have a minimum occurance of zero or more, a maximum occurance of 1 or more (possibly unlimited), and may or may not be required. A given element may or may not be represented as an an attribute. These things I will also know at runtime, and these can also change at runtime - even between unmarshalling and marshalling.
The problem is that although we can almost map this to a HashMap, because it requires unique keys, and we are keying on the element name, we can't have duplicate elements - which the structure says we have to support. This is how I discovered we had a problem.
I am thinking that I want to just unmarshall this structure into a simple List. I already have the Element structure (sans values) in a list - so I am thinking I would like to extend the classes in that list to not only have the strucutral and type info, but also contain the value, then when I unmarshall the XML I can almost directly use the List.
My question/problem:
I am thinking I would generate a mapping file on the fly, when I know the general structure of this particular snippet of XML. That should not be hard at all.
I am thinking that I also need to use a FieldHandler of some sort - but I am not sure and I haven't been able to find enough documentation/examples/hand-holding of FieldHandlers to make me feel comfortable going down the road just yet.
Does this seem a reasonable way to attack this problem?
Are there some detailed/hand-holding examples somewhere?
I have read everything I could find on the Castor website and linked articles therein.
Other suggestions? Tips? Traps? Tricks?
TIA
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
