Nico AD
Nico AD

Reputation: 1709

working with XML on Android

I m new to Android (porting iOS/Objective C app ) and I have to read an XML (with some nodes in JSON) file returned by a WebService

the response looks like that:

<SOAP-ENV:Envelope><SOAP-ENV:Body><ns1:TPLoginResponse><TPLoginResult>[{"content": "some json content...."]</TPLoginResult></ns1:TPLoginResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

how can I simply get the content of TPLoginResult ?

I tried :

            httpTransport.call(SOAP_ACTION, envelope);

            Object response = envelope.getResponse();

            SoapObject SoapResponse = (SoapObject)envelope.bodyIn;

            Log.e("Info",  "response : " + SoapResponse.toString() ); // content is successfully received here 

            String SResponse =  SoapResponse.toString();

            Log.e("Info",  "DocumentBuilderFactory" );

            // parse the XML as a W3C Document
            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            builderFactory.setNamespaceAware(true);
            DocumentBuilder builder = builderFactory.newDocumentBuilder();

            Document document = builder.parse( new InputSource(new StringReader(SResponse)) );

             NodeList nList = document.getElementsByTagName("TPLoginResult");

             Log.e("info","nList length : " + nList.getLength());

but I need a 0 length nList ...

I also tryed :

  NodeList nList = document.getElementsByTagName("ns1:TPLoginResponse");

but same 0 length result..

Any suggestions ?

Upvotes: 1

Views: 163

Answers (3)

Nico AD
Nico AD

Reputation: 1709

Finally I found that it is more easy usign the ksoap methods

String LoginResponse = SoapResponse.getProperty(0).toString();

Upvotes: 0

Jan
Jan

Reputation: 400

KSOAP Android is a very useful tool to consume SOAP web-services. I use this tool in all my Android applications. And I can say that it works well.

You can find examples in their wiki and all over internet.

Upvotes: 1

Th0rndike
Th0rndike

Reputation: 3436

I think the key is in this line:

builderFactory.setNamespaceAware(true);

if you comment that line you'd be able to get the element with

document.getElementsByTagName("TPLoginResponse");

otherwise, you'll probably need to use:

document.getElementsByTagNameNS(namespaceURI,tag);

but i have never used the last line, so i can't help you there.

please let me know how that works for you, i'm interested.

Upvotes: 1

Related Questions