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

Beacon

--



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);
request.addProperty("token",WebPage.token);
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=
\"UTF-8\"?>");
androidHttpTransport.call(SOAP_ACTION, 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


 Hi,

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
case?

Best regards,
Filip Havlicek

2010/7/31 beacon <indiantalkiedhi...@gmail.com>


>



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.

    envelope.addMapping(request.getNamespace(),
                        "MyDotNetClassName",
                        MyAndroidClass.class);

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

Ed





--



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 =
DocumentBuilderFactory.newInstance();
        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))
                {
                        Log.d("Property1", 
property.getFirstChild().getNodeValue());
                }
        }
}

//a.xml
<root>
        <item>
                <property1>Iamproperty1</property1>
        </item>
</root>




--



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.

beacon






--



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.

beacon





--



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 <indiantalkiedhi...@gmail.com>



> > >



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 = " http://tempuri.org/" ;;
        private static final String METHOD_NAME = "GetProfileDataXML";
        private static final String URL = " http://mobileexchange.ctisinc.com/ 
CTISGDataService.svc";
        private static final String SOAP_ACTION = " http://tempuri.org/ 
ICTISGDataService/GetProfileDataXML";



With regards,

Beacon





> > > >



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
having!

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 <indiantalkiedhi...@gmail.com> 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,

Beacon

On Aug 2, 1:23pm, Bob Kerns <r...@acm.org> 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 http://www.devx.com/wireless/Article/39810/1954
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: 
http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml

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.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
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.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

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

public class httpDownload extends Activity {
    /** Called when the activity is first created. */
        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ArrayList<String> dataReturned = DownloadRSS("http://
newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml");

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

         Bitmap bitmap =
             DownloadImage(dataReturned.get(1));
         ImageView img = (ImageView) findViewById(R.id.img);
         img.setImageBitmap(bitmap);

        }


    }

    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");

        try{
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod("GET");
            httpConn.connect();

            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);
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        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 =
                DocumentBuilderFactory.newInstance();
            DocumentBuilder db;

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

            doc.getDocumentElement().normalize();
            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 =
itemElement.getElementsByTagName("title");
                    Element titleElement = (Element) titleNodes.item
(0);

                    NodeList imgNodes =
itemElement.getElementsByTagName("media:thumbnail");
                    Element imgElement = (Element) imgNodes.item(0);

                    NodeList textNodes = titleElement.getChildNodes();

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

                    dataArray.add(strTitle);
                    dataArray.add(strImg);

                }
            }

        } catch (IOException e1) {

            e1.printStackTrace();
        }
        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.



Thanks,
Shibbs





--~--~---------~--~----~------------~-------~--~----~

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 http://source.android.com/using-eclips

7. problems building android dev environment?