Retrieving XML Document from web service

by beacon » Sat, 31 Jul 2010 06:35:25 GMT

Sponsored Links
 Hi ,

 I am trying to retrieve a XML document from web service. I am passing
a soap object with a token implementing the OAuth concept and
retrieving the data. But the data does not turn out to be in XML
format. It contains a curly braces in the place of start tag and
semicolons when it ends. Is there any way to retrieve the document in
XML format as such?

Thank you



Retrieving XML Document from web service

by Carlos Silva » Sat, 31 Jul 2010 06:39:58 GMT

Retrieving XML Document from web service

by beacon » Sat, 31 Jul 2010 06:45:43 GMT

 Thanks for your reply. But it is not similar to JSON. My sample data
looks something like this

anyType{ProductName=anyType{Text=Nadolol; Code=anyType{Value=11755;
CodingSystem=FDB_routed; }; Code=anyType{Value=20.55472;
CodingSystem=Google; }; Code=anyType{Value=7870; CodingSystem=FDB; };
Code=anyType{Value=19.9453; CodingSystem=Google; }; }; }

And I have confirmed with the web service and they have assured that
they send back the data in XML format. But I am not able to get it in
XML format.


Retrieving XML Document from web service

by Frank Weiss » Sat, 31 Jul 2010 07:06:01 GMT

 I don't recognize what data format that is, but I would guess that
your code has an error or is not sending the right HTTP headers. What
client side code are you using?


Retrieving XML Document from web service

by beacon » Sat, 31 Jul 2010 07:29:16 GMT

 Hello Frank,

This is what I am doing on the client side

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=
\"UTF-8\"?>");, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
String strResult = result.toString();

I am getting all the fields that I am supposed to get, but I am not
getting it in the XML format.That's my problem.


Retrieving XML Document from web service

by Filip Havlicek » Sun, 01 Aug 2010 13:08:14 GMT


just a quick thought about that - some web services have a request property
to define in what format you want the result. Are you sure this isn't your

Best regards,
Filip Havlicek

2010/7/31 beacon <>


Retrieving XML Document from web service

by Ed » Mon, 02 Aug 2010 10:56:31 GMT

 Add this for all the classes you're using. This will let KSoap2 know
what java classes handle the each response element.


For others trying to help this is the KSoap2 toString() once KSoap2
has parsed the XML response.



Retrieving XML Document from web service

by CMF » Mon, 02 Aug 2010 11:26:59 GMT

 I dont know if it is suitable for your case, but I can retrieve the
xml document for the web with the following method

URL mURL= new URL("http://XXXXX/a.xml");
http = (HttpURLConnection) mURL.openConnection();
int nRC = http.getResponseCode();
if (nRC == HttpURLConnection.HTTP_OK)
        DocumentBuilderFactory factory =
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document dom = builder.parse(mURL.openConnection().getInputStream());
        Element root = dom.getDocumentElement();
        NodeList items = root.getElementsByTagName("item");
        for(int i=0; i<items.getLength(); i++)
                Node property = properties.item(j);
                String name = property.getNodeName();
                if (name.equalsIgnoreCase("property1))



Retrieving XML Document from web service

by beacon » Mon, 02 Aug 2010 22:13:42 GMT

 Hi Filip,

  It doesn't seem to be the case, as the web service does not give me
any option it just sends XML response whatever it is.

> >

Retrieving XML Document from web service

by beacon » Mon, 02 Aug 2010 22:16:18 GMT

 Hello Ed,

   Thanks for your response. I added the code snippet to me requesting/
receiving class . But  I still get the response in the same format as
mentioned above. I am not sure why.



Retrieving XML Document from web service

by beacon » Mon, 02 Aug 2010 22:17:21 GMT

 Hello CMF,

             Thanks for your reply. But I dont think I can use this
kind of approach as I need to send a soap object to the web service
and nothing else and it also implements OAuth.



Retrieving XML Document from web service

by Filip Havlicek » Mon, 02 Aug 2010 23:07:59 GMT

 Hi Beacon,

it would probably be the best if you could give as a link to the service you
are trying to use. We could at least look into the website to see if you are
not missing something, because this just doesn't look like XML at all afaik.

Best regards,
Filip Havlicek

2010/8/2 beacon <>

> > >

Retrieving XML Document from web service

by beacon » Mon, 02 Aug 2010 23:33:14 GMT

 Hi Filip,

  Thanks for your reply. Sure I could give that. This is the what I am
trying to access.

      private static final String NAMESPACE = "" ;;
        private static final String METHOD_NAME = "GetProfileDataXML";
        private static final String URL = " 
        private static final String SOAP_ACTION = " 

With regards,


> > > >

Retrieving XML Document from web service

by Bob Kerns » Tue, 03 Aug 2010 01:23:29 GMT

 hat Ed is telling you (and the other people trying to help) is that
what you are seeing is NOT the format that the server is ending.

In fact, it would be somewhat difficult for you to actually see that
data in your program and also parse it.

What you are seeing is the result of (implicitly) calling toString()
on the objects that are being returned, which is in a compact format
intended for developers. Not necessarily a good format, but that's
basically irrelevant. You are not having the problem you think you are

The fact that you are getting this output at all means that you ARE
successfully receiving and parsing the XML. In fact, from the presence
of the 'anyType' tokens, I am guessing it has even been through XML
Schema Validation.

If you wanted to see the actual data, you'd have to open the
connection yourself using the same URL, post the same data if using
POST, and then read the result as a series bytes, convert to
characters (using a Reader) and output the result. I haven't a clue
how you'd manage to do this and get KSoap to also process it; I
wouldn't even try.

So the bottom line is -- the problem you think you face basically
doesn't exist. Your next step is to make use of that returned data
through the provided APIs.

On Aug 2, 7:15am, beacon <> wrote:


Retrieving XML Document from web service

by beacon » Tue, 03 Aug 2010 03:06:00 GMT

 hanks for your reply Bob. I got hold of whats happening now. I will
look in to it. Thank you,


On Aug 2, 1:23pm, Bob Kerns <> wrote:


Other Threads

1. getting the value from an attribute of an element in an rss xml feed

hi folks,

i've been struggling to find a way to read in a url value from within
a tag in an xml feed. im so close but i just can't seem to crack it.

i started out using this
as a guide which works great but customising it to read in an
attribute of an element is causing me problems.

the feed is here:

within the xml's 'item' element is <media:thumbnail width="X"
height="X" url="X"/> it's the url attribute im after. i can get the
title back fine but the structure of the media:thumbnail tag means im
missing something!

what's interesting(!?) is the fact that when i remove the loop and
only go for the first item, i get the image back! the line with strImg
= imgElement.getAttribute("url") just won't work within the loop...
any ideas are greatly appreciated.

this is very rough n ready, im learning :-)


package apps.httpDownload;

import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import android.os.Bundle;

import android.widget.ImageView;
import android.widget.TextView;

public class httpDownload extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        ArrayList<String> dataReturned = DownloadRSS("http://");

        TextView txt = (TextView) findViewById(;
        for (int i = 0; i < dataReturned.size(); i++) {
         if (i < 10)
         txt.setText(txt.getText() + "\n" + dataReturned.get(i)  +

         Bitmap bitmap =
         ImageView img = (ImageView) findViewById(;



    private InputStream OpenHttpConnection(String urlString)
    throws IOException
        InputStream in = null;
        int response = -1;

        URL url = new URL(urlString);
        URLConnection conn = url.openConnection();

        if (!(conn instanceof HttpURLConnection))
            throw new IOException("Not an HTTP connection");

            HttpURLConnection httpConn = (HttpURLConnection) conn;

            response = httpConn.getResponseCode();
            if (response == HttpURLConnection.HTTP_OK) {
                in = httpConn.getInputStream();
        catch (Exception ex)
            throw new IOException("Error connecting");
        return in;

    private Bitmap DownloadImage(String URL)
        Bitmap bitmap = null;
        InputStream in = null;
        try {
            in = OpenHttpConnection(URL);
            bitmap = BitmapFactory.decodeStream(in);
        } catch (IOException e1) {
        return bitmap;

    private ArrayList<String> DownloadRSS(String URL)

        ArrayList<String> dataArray = new ArrayList<String>();
        InputStream in = null;
        try {
            in = OpenHttpConnection(URL);
            Document doc = null;
            DocumentBuilderFactory dbf =
            DocumentBuilder db;

            try {
                db = dbf.newDocumentBuilder();
                doc = db.parse(in);
            } catch (ParserConfigurationException e) {
            } catch (SAXException e) {

            NodeList itemNodes = doc.getElementsByTagName("item");
            String strTitle = "";
            String strImg = "";

            for (int i = 0; i < itemNodes.getLength(); i++) {
                Node itemNode = itemNodes.item(i);
                if (itemNode.getNodeType() == Node.ELEMENT_NODE)
                    Element itemElement = (Element) itemNode;

                    NodeList titleNodes =
                    Element titleElement = (Element) titleNodes.item

                    NodeList imgNodes =
                    Element imgElement = (Element) imgNodes.item(0);

                    NodeList textNodes = titleElement.getChildNodes();

                    strTitle = ((Node) textNodes.item(0)).getNodeValue
                    //strImg = imgElement.getAttribute("url");



        } catch (IOException e1) {

        return dataArray;




2. Build Contact "Stand Alone" apk - from Android Contact Source Code?

Hi Mark,

Thanks for the response.

Yes that's exactly what I am trying to do.

As suggested, If i remove all the internal api calls (mentioned in my
previous mail), I may have to compromise / even break some of the
functionality of Contacts app.

I am trying to add more features to the existing contacts app, without
loosing any of existing contacts functionality. Is it possible?
Well this is what my intended direction, where I am heading, without
knowing if that is possible.



3. "Android app revenues averaged $62.39 per day....very difficult to buy the summer home at this rate"

4. Android supports audio bookmarking

5. problems building android dev environment?

6. problems building an eclipse dev environment as described on

7. problems building android dev environment?