Click here to Skip to main content
15,908,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am new for android developing and i am trying to get a xml list to android from self-created listview.

I am looking for some examples but they are using only one example about fahrenheit to calcius. So i need to get full list of web service.

Here is my code;

C#
private static String SOAP_ACTION1 = "http://tempuri.org/kategoriler";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME1 = "kategoriler";
private static String URL = "http://xxx.xxxxx.com/Service1.asmx";

   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            envelope.dotNet = true;
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION1, envelope);
            SoapObject result = (SoapObject)envelope.bodyIn;

            if(result != null)
            {
                for (int i = 0 ; i<= result.getPropertyCount();i++) {

                    Object property = result.getProperty(i);
                    if (property instanceof SoapObject) {
                        SoapObject info = (SoapObject) property;
                        String id = info.getProperty("id").toString();
                        String resim = info.getProperty("resim").toString();
                        String kategori_adi = info.getProperty("kategori_adi").toString();
                        Toast.makeText(getApplicationContext(), kategori_adi, Toast.LENGTH_LONG).show();   

                    }   
                }
            }
            else
            {
                Toast.makeText(getApplicationContext(), "No Response", Toast.LENGTH_LONG).show();
            }
        }
        catch (Exception ex) {
            Toast.makeText(getApplicationContext(),ex.getMessage(), Toast.LENGTH_SHORT).show();
        }

    }


When i tried to run this project it gave me unfortu... stopped. My web service file is

C#
<DataSet xmlns="http://tempuri.org/">
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:int" minOccurs="0"/>
<xs:element name="kategori_adi" type="xs:string" minOccurs="0"/>
<xs:element name="resim" type="xs:string" minOccurs="0"/>
<xs:element name="kategori_no" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<id>1</id>
<kategori_adi>Arkadaşlık & Sohbet</kategori_adi>
<resim>
kategoriresim/eb5b34ba-2ec4-4c96-9ade-4653a01c2a2fa1.jpg
</resim>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
<id>2</id>
<kategori_adi>Bilgisayar & Internet</kategori_adi>
<resim>
kategoriresim/eb5b34ba-2ec4-4c96-9ade-4653a01c2afa2.jpg
</resim>
</Table>
<Table diffgr:id="Table3" msdata:rowOrder="2">
<id>5</id>
<kategori_adi>Astroloji & Burç</kategori_adi>
<resim>
kategoriresim/eb5b34ba-2ec4-4c96-9ade-4653a01c2afa3.jpg
</resim>
<kategori_no>123</kategori_no>
</Table>
<Table diffgr:id="Table4" msdata:rowOrder="3">
<id>7</id>
<kategori_adi>Yazılım & Tasarım</kategori_adi>
<resim>
kategoriresim/966bad7b-7f0b-4ded-8759-9f19bbc894b2.jpg
</resim>
<kategori_no>1234</kategori_no>
</Table>
<Table diffgr:id="Table5" msdata:rowOrder="4">
<id>8</id>
<kategori_adi>Kişisel & Blog</kategori_adi>
<resim>
kategoriresim/7b8cc2d2-6d07-4ea4-92b6-c99316eb2b04.jpg
</resim>
<kategori_no>214</kategori_no>
</Table>
Posted

1 solution

Use
C#
using System.Xml;
library in C#


C#
StringBuilder output = new StringBuilder();

String xmlString =
        @"<?xml version='1.0'?>
        <!-- This is a sample XML document -->
        <Items>
          <Item>test with a child element <more/> stuff</Item>
        </Items>";
// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
    XmlWriterSettings ws = new XmlWriterSettings();
    ws.Indent = true;
    using (XmlWriter writer = XmlWriter.Create(output, ws))
    {

        // Parse the file and display each of the nodes.
        while (reader.Read())
        {
            switch (reader.NodeType)
            {
                case XmlNodeType.Element:
                    writer.WriteStartElement(reader.Name);
                    break;
                case XmlNodeType.Text:
                    writer.WriteString(reader.Value);
                    break;
                case XmlNodeType.XmlDeclaration:
                case XmlNodeType.ProcessingInstruction:
                    writer.WriteProcessingInstruction(reader.Name, reader.Value);
                    break;
                case XmlNodeType.Comment:
                    writer.WriteComment(reader.Value);
                    break;
                case XmlNodeType.EndElement:
                    writer.WriteFullEndElement();
                    break;
            }
        }

    }
}
OutputTextBlock.Text = output.ToString();


from How to: Parse XML with XmlReader[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900