Re: [Simple-support] Inline list of simple elements with different names
Brought to you by:
niallg
|
From: Jarrod S. <ja...@co...> - 2011-11-11 09:06:19
|
So in a nutshell I need something that does the equivalent of:
@ElementList(entry = "*", type = GenericAPIError.class)
i.e. A wildcard for the entry parameter, and have it not care about
the element name.
On Fri, Nov 11, 2011 at 8:03 PM, Jarrod Smith <ja...@co...> wrote:
> Thanks Niall,
>
> The XML response is of this form:
>
> <FAIL>
>
> <A>Error relating to A</A>
> <B>Error relating to B</B>
> <C>Error relating to C</C>
> ...
> <ERROR>General Error Message 1</ERROR>
> <ERROR>General Error Message 2</ERROR>
> <ERROR>General Error Message 3</ERROR>
> ...
> </FAIL>
>
> But I don't know what the A, B, C elements are actually named, only
> that they just contain text, and won't be nested.
>
> I'm currently using an ElementListUnion which gets me halfway there,
> but that still requires that I know what all the element names are
> (which I can only find out by trial and error, which will take
> forever). So I need a way to just parse the simple document format
> above, and just chuck all the element values into a list, array,
> whatever.
>
> Below is basically what I'm using at the moment, you can see the
> different types of error element names I've managed to discover so
> far.
>
> @Root(strict=false)
> public class MyServerResponseErrorParser
> {
>
> @ElementListUnion({
> @ElementList(entry = "ERROR", inline = true, required = false, type
> = GenericAPIError.class),
> @ElementList(entry = "CONTACT", inline = true, required = false,
> type = GenericAPIError.class),
> @ElementList(entry = "SIGNUP", inline = true, required = false, type
> = GenericAPIError.class),
> @ElementList(entry = "PLAN", inline = true, required = false, type =
> GenericAPIError.class),
> @ElementList(entry = "PAYMENT", inline = true, required = false,
> type = GenericAPIError.class),
> @ElementList(entry = "PLAN_ID", inline = true, required = false,
> type = GenericAPIError.class)})
> public List<GenericAPIError> errors;
>
> }
>
> @Root
> public class GenericAPIError
> {
> @Text
> public String error;
> }
>
>
> Thanks a lot,
> Jarrod.
>
> On Fri, Nov 11, 2011 at 7:19 PM, Niall Gallagher
> <gal...@ya...> wrote:
>>
>> If you provide a code example with some xml ill see what the solution should be
>>
>> Sent from Yahoo!7 Mail on Android
>>
>> ________________________________
>> From: Jarrod Smith <ja...@co...>;
>> To: <sim...@li...>;
>> Subject: Re: [Simple-support] Inline list of simple elements with different names
>> Sent: Fri, Nov 11, 2011 12:35:22 AM
>>
>> I just found this thread:
>> http://sourceforge.net/mailarchive/message.php?msg_id=26681126
>>
>> Cameron's was the exact same problem I am having. So it seems there is
>> no way around this, without a setName() on the InputNode. Niall I
>> don't understand your final suggestion in that thread to "use the
>> Style interface" since that only applies to serialisation to XML, and
>> not deserialising *from* XML, which is when Cameron and I are needing
>> to modify the element names. Or am I missing something?
>>
>> To be clear, what I want to do is rename the <A>, <B>, <C> ... etc.
>> elements below to all be <ERROR> nodes.
>>
>> Any suggestions greatly appreciated.
>>
>> - Jarrod
>>
>> On Sun, Nov 6, 2011 at 9:37 PM, Jarrod Smith <ja...@co...> wrote:
>> > I have a doc that has something like the following structure:
>> >
>> > <FAIL | OK>
>> >
>> > <!-- In the FAIL Case: -->
>> >
>> > <A>Error relating to A</A>
>> > <B>Error relating to B</B>
>> > <C>Error relating to C</C>
>> > ...
>> > <ERROR>General Error Message</ERROR>
>> > <ERROR>General Error Message</ERROR>
>> > <ERROR>General Error Message</ERROR>
>> > ...
>> > </FAIL | OK>
>> >
>> > There could be a lot of different A, B, C, ...., and to make matters
>> > worse, I haven't even been provided with a specification as to what
>> > they all could be.
>> >
>> > The contents of the elements is always just a string. So the document
>> > is really just a flat list of elements containing strings. Is there a
>> > simple way for me to declare a Class to parse this?
>> >
>> > Something like:
>> >
>> > @Root
>> > public class MyErrorClass {
>> > @ElementList(inline=true)
>> > public List<APIError> errors;
>> > }
>> >
>> > @Root // <--- Don't want this to care about
>> > the name of the element.
>> > public class APIError
>> > {
>> > @Text
>> > String error;
>> > }
>> >
>> > Another idea I had was to just use a Visitor to stomp all the element
>> > names and just make them all ERROR. But it doesn't look like you can
>> > change the element name of an InputNode. Anyway, this idea would only
>> > work if the TreeStrategy visits the document Root node before any
>> > others, so I could set a flag indicating this was a <FAIL> document.
>> >
>> > Any suggestions appreciated.
>> >
>>
>> ------------------------------------------------------------------------------
>> RSA(R) Conference 2012
>> Save $700 by Nov 18
>> Register now
>> http://p.sf.net/sfu/rsa-sfdev2dev1
>> _______________________________________________
>> Simple-support mailing list
>> Sim...@li...
>> https://lists.sourceforge.net/lists/listinfo/simple-support
>
|