Re: [Simple-support] Inline list of simple elements with different names
Brought to you by:
niallg
|
From: Jarrod S. <ja...@co...> - 2011-11-11 00:35:30
|
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. > |