Hi everybody.
I´m trying to unmarshall an xml file with no namespace, I have the structure
bellow in that file:
<a>
<b>
<c>
<name index=1>NameOne</name>
<name index=2>NameTwo</name>
<name index=3>NameThree</name>
</c>
</b>
</a>
So I need to assign the second occur(NameTwo) of the tag name to a String
property in my class "Dog", the property's name is "name".
My Class is something like this:
public class Dog{
private String name;
public Dog(){
}
public String getName(){
return this.name;
}
public void setName(String name){
this.name = name;
}
}
Finally my mapping.xml have the follow structure to unmarshall the xml file.
<class name="Dog">
<map-to xml="a"/>
<field name="name" type="java.lang.String">
<bind-xml name="name" node="element" location="b/c"/>
</field>
</class>
If I try to unmarshaller the xml file with that Structorure Castor throw me
an exception tell me "Element "name" occur more than once".
The key point that is in the line ( <bind-xml name="name" node="element"
location="b/c"/> ) How can I tell to castor that I need the second occur of
name
( <name index=2>NameTwo</name> )?
I can't change the xml to put a nameSpace, when I used DOM whith XPATH I
would use a XPATH like this: "a/b/c/name[position()=2]". there is any way to
do something like this with castor.
Thanks in advance.
CesarGuzman.