[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ksoap: Sending and receiving Elements / kSOAP and kXML updates


Stefan,

THANK YOU VERY MUCH... I was parsing only the body... ( envelope.parseBody() ) and
that's why ...

thanks a lot

montse


> Montse Farreras - Sun France - GSO - Stagiaire wrote:
> >
> > I got ClassCastException again... :-(
> > more ideas??
>
> I tried it with a Phone class and your
> XML code and it works without problems.
>
> Just compare your code with the
> PhoneSample attached.
>
> Best,
> Stefan
>
> --
> Stefan Haustein
> Univ. Dortmund, FB 4, LS 8   tel: +49 231 755 2499
> Baroper Str. 301             fax: +49 231 755 5105
> D-44221 Dortmund (Germany)   www-ai.cs.uni-dortmund.de
>
>   ------------------------------------------------------------------------
> import java.io.*;
> import org.ksoap.*;
> import org.kxml.*;
> import org.kxml.parser.*;
>
> public class PhoneSample {
>
>     public static void main (String [] argv) throws IOException {
>
>         DefaultClassMap classMap = new DefaultClassMap (true);
>         classMap.setMapping ("urn:xml-soap-address-demo", "phone", Phone.class);
>
>         SoapEnvelope envelope = new SoapEnvelope ();
>         envelope.setClassMap (classMap);
>
>         XmlParser parser = new XmlParser (new FileReader ("response.xml"));
>
>         envelope.parse (parser);
>
>         Phone phone = (Phone) envelope.getResult ();
>
>         System.out.println ("exchange: "+phone.exchange);
>         System.out.println ("areaCode: "+phone.areaCode);
>         System.out.println ("number:   "+phone.number);
>
>     }
>
> }
>
>   ------------------------------------------------------------------------
> import org.ksoap.*;
>
> public class Phone implements KvmSerializable {
>
>     String exchange;
>     int areaCode;
>     String number;
>
>     public Object getProperty (int index) {
>         switch (index) {
>         case 0: return exchange;
>         case 1: return new Integer (areaCode);
>         case 2: return number;
>         default: throw new RuntimeException ();
>         }
>     }
>
>     public int getPropertyCount () {
>         return 3;
>     }
>
>     public void getPropertyInfo (int index, PropertyInfo info) {
>         switch (index) {
>         case 0:
>             info.name = "exchange";
>             info.type = String.class;
>             break;
>         case 1:
>             info.name = "areaCode";
>             info.type = Integer.class;
>             break;
>         case 2:
>             info.name = "number";
>             info.type = String.class;
>             break;
>         default:
>             throw new RuntimeException ();
>         }
>     }
>
>     public void setProperty (int index, Object value) {
>         switch (index) {
>         case 0: exchange = (String) value; break;
>         case 1: areaCode = ((Integer) value).intValue (); break;
>         case 2: number = (String) value; break;
>         default: throw new RuntimeException ();
>         }
>     }
>
> }
>
>   ------------------------------------------------------------------------
>
> <SOAP-ENV:Envelope
> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
> xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance";
> xmlns:xsd="http://www.w3.org/1999/XMLSchema";>
> <SOAP-ENV:Body>
> <ns1:getPhoneFromNameResponse
> xmlns:ns1="urn:AddressFetcher"
> SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";>
> <return xmlns:ns2="urn:xml-soap-address-demo"
> xsi:type="ns2:phone">
> <exchange xsi:type="xsd:string">456</exchange>
> <areaCode xsi:type="xsd:int">123</areaCode>
> <number xsi:type="xsd:string">7890</number>
> </return>
> </ns1:getPhoneFromNameResponse>
>
> </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>