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