[Simple-support] How to deserialize an heterogeneous sequence of elements
Brought to you by:
niallg
|
From: RaphaelJ <rap...@gm...> - 2011-03-02 12:05:06
|
Hello,
I have an XML file that looks like this :
/------------------- sample-script.xml -------------------------\
<script>
<copy srcDir="src" destDir="dest" filePattern="*.dep" />
<cleanDir dir="log" />
<!-- Other commands .... -->
</script>
\-------------------------- END -------------------------------/
I want to parse the sequence of commands, each type of command transforming
into a different class.
I would like to avoid the use of "class='foo.Bar'" attributes.
Here are 3 classes :
/------------------- Script.java ------------------------------\
@Root(name="script")
public class Script {
@ElementList(inline=true)
private List<ICommand> commands;
}
\-------------------------- END -----------------------------/
/--------------- CommandCopy.java -------------------------\
@Root(name="copy")
public class CommandCopy implements ICommand {
@Attribute
private String srcDir;
@Attribute
private String destDir;
@Attribute(required=false)
private String fileFilter = "*.*";
}
\------------------------ END ---------------------------------/
/-------------- CommandCleanDir.java -------------------------\
@Root(name="cleanDir")
public class CommandCleanDir implements ICommand {
// -- Attributes
@Attribute
private String dir;
}
\------------------------ END ---------------------------------/
All those classes are in the same package.
When I try parse this, I get the following error :
org.simpleframework.xml.core.ElementException: Element 'copy' does not have
a match in class fr.whatever.Script at line -1
I think that Simple-XML could guess the class I want to instantiate, based
on the @Root(name="something") annotation of the class. Should I register
all the possible classes somewhere ? Or does simùple-XML finds out all
annotated classes on his own ?
Is there some way to achieve what I want with Simple-XML ?
Thanks in advance for your help.
Raphael
--
View this message in context: http://old.nabble.com/How-to-deserialize-an-heterogeneous-sequence-of-elements-tp30985952p30985952.html
Sent from the Simple XML Serialization mailing list archive at Nabble.com.
|