Hi Cesar,

I am afraid that that won't be able with Castor - for several reasons,
that is.

a) Provided the mapping you are using, the XML does not match the
structure you have defined in your mapping. Your field mapping

<field name="name" type="java.lang.String">
  <bind-xml name="name" node="element" location="b/c"/>
</field>

indicates that the 'name' property of your Dog class does not allow
multi-valuedness. That's your first break.

b) You are slightly mis-interpreting the location attribute. This
attribute is designed to allow pre-pending XML artefacts that you do not
want to have in your Java POJOs. It is a structural element only, and
not designed to be used to identify specific occurrences of XML
artefacts at run-time.

Regards
Werner

Cesar Guzman wrote:
> 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.
> 

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to