Great !!!! now it works ! God bless you ! Thanks !

Lukas Lang wrote:
> 
> Hey Francesco,
> 
> There is one major mistake in your Mapping file:
> 
> Castor does not know, which element name the DialPlan object should be
> associated with.
> 
> The following mapping works fine for me:
> 
> <?xml version="1.0"?>
> <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
>                            "http://castor.org/mapping.dtd";>
> <mapping>
>     <class name="xml.template.BaseCommand">
>         <map-to xml="ccsmp-create" />
>         <field name="sessionId" type="java.lang.String">
>             <bind-xml name="session" node="attribute" />
>         </field>
>         <field name="dialplans" type="xml.template.DialPlan"
> collection="arraylist">
>             <bind-xml name="DialPlan" />
>         </field>
>     </class>
> 
>     <class name="xml.template.DialPlan">
>         <field name="entId" type="java.lang.String">
>             <bind-xml name="ent-id" node="attribute" />
>         </field>
>         <field name="name" type="java.lang.String">
>             <bind-xml name="name" node="attribute" />
>         </field>
>     </class>
> </mapping>
> 
> The second mistake, I notices is located at the addDialplan method, which
> should be called 'addDialplans(...)'
> This is, how I marshalled/unmarshalled the objects:
> 
> <code>
> XMLContext context = new XMLContext();
> Mapping mapping = new Mapping();
> mapping.loadMapping(getClass().getResource("mapping.xml").toExternalForm());
> 
> this.context.addMapping(mapping);
> Unmarshaller unmarshaller = context.createUnmarshaller();
> unmarshaller.setClass(BaseCommand.class);
> 
> BaseCommand cmd = (BaseCommand) unmarshaller.unmarshal(new
> InputSource(getClass().getResource(SAMPLE_FILE).toExternalForm()));
> </code>
> 
> You could also add the whole package.
> Hope, it helped ;-)
> 
> Regards,
> Lukas
> 
> fmarchioni schrieb:
>> 
>> Werner Guttmann wrote:
>>> You are using one of the static unmarshal methods, which will ignore any
>>>  mapping defined by you. Can you please switch to a non-static one, and
>>> see whether it works ?
>>>
>> 
>> Hi, thank you very much for your reply. using non-static methods I am
>> able
>> to retreive
>> the Wrapper object (ccsmp-create) ...but I get an empty DialPlan....
>> 
>> <?xml version="1.0" encoding="UTF-8"?>
>> <ccsmp-create session="8u8989h789h9h8989"> <----This one I can find it
>> <DialPlan ent-id="name" name="333"/>             <---- The hidden object
>> is
>> not  found !
>> </ccsmp-create>
>> 
>> 
>> This is how I coded it:
>> 
>> public class BaseCommand {
>>    String sessionId;
>> 
>> public String getSessionId() {
>>      return sessionId;
>> }
>> 
>> public void setSessionId(String sessionId) {
>>      this.sessionId = sessionId;
>> }
>> 
>> public List  dialplans = new ArrayList();
>> 
>> public void addDialplan(DialPlan dialplan) {
>>      dialplans.add(dialplan);
>> }
>> 
>> public List getDialplans() {
>>   return dialplans;
>> }
>> 
>> -------------------------------------------------
>> 
>> public class DialPlan {
>>   String entId;
>>   String name;
>>   // getter and setters here
>> }
>> 
>> ---------------------------------------------->mapping.xml
>> 
>> <mapping>
>> 
>> <class name="BaseCommand">
>>   <map-to xml="ccsmp-create" />
>>     
>>   <field name="sessionId" type="java.lang.String">
>>      <bind-xml name="session" node="attribute"  />
>>   </field>
>>   
>>   <field name="dialplans" type="DialPlan" collection="collection" />
>> </class>
>> 
>>   
>>     <class name="DialPlan">
>>               
>>     <field name="entId" type="java.lang.String">
>>         <bind-xml name="ent-id" node="attribute"  />
>>     </field>
>>         <field name="name" type="java.lang.String">
>>         <bind-xml name="name" node="attribute"  />
>>     </field>
>>   </class> 
>>   
>> </mapping>
>> 
>> 
>> ---------------------------------------------------------->data.xml
>> <?xml version="1.0" encoding="UTF-8"?>
>> <ccsmp-create session="8u8989h789h9h8989">
>> <DialPlan ent-id="name" name="333"/>
>> </ccsmp-create>
>> ------------------------------------------------------------->Client Java
>> and I unmarshal it this way:
>> 
>> Mapping mapping = new Mapping();
>> mapping.loadMapping("mapping.xml");
>> 
>> Unmarshaller un = new Unmarshaller(BaseCommand.class);
>> un.setMapping( mapping );
>> 
>> FileReader in = new FileReader("data.xml");
>> BaseCommand plan = (BaseCommand) un.unmarshal(in);
>> in.close();
>> 
>> System.out.println(plan.getSessionId());  // This data is found
>> List list = plan.getDialplans();                // No data found !
>> 
>> --------------------------
>> Please help, I'm fighting with this since this morning :-(
>> thanks a lot
>> francesco
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
> 
>     http://xircles.codehaus.org/manage_email
> 
> 
> 
> 
:clap:
-- 
View this message in context: 
http://www.nabble.com/Unmarshalling-of-nested-XML-tp19914206p19917197.html
Sent from the Castor - User mailing list archive at Nabble.com.


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

    http://xircles.codehaus.org/manage_email


Reply via email to