how to get the values from soap response in android? - android

the following xml tag for webservice response ,i dont know how to parse it..help me..
<NewDataSet>
<JOBLIST>
<CSIDNO>CS13224</CSIDNO>
<PName>Selva</PName>
<HouseID>G 34</HouseID>
<NAME>Dilipan</NAME>
<Address>Coimbatore</Address>
</JOBLIST>
<JOBLIST>
<CSIDNO>CS13224</CSIDNO>
<PName>Selva</PName>
<HouseID>G 35</HouseID>
<NAME>Kanrupannan</NAME>
<Address>Coimbatore</Address>
</JOBLIST>
</NewDataSet>
i am using the following java code .....
for(int i=0;i<result.getPropertyCount();i++)
{
SoapObject ob=(SoapObject)result.getProperty(i);
homeid[i]=String.valueOf(ob.getProperty("HouseID"));
namearr[i]=String.valueOf(ob.getProperty("NAME"));
address[i]=String.valueOf(ob.getProperty("Address"));
csidno[i]=String.valueOf(ob.getProperty("CSIDNO"));
}
how to get the values form xml tag..

Why using Soap there are different kinds of parsing methods you can use one of them. Parsing methods are SAXParser, Json parser, DOM parser, XML pull parser. In yourt situation SAX parser will be good to parse. see this and this tutorial. It will help you in parsing the xml you are receiving. Let me know if they helps you

Its pretty simple you have to get the respose as a string and use pattern matches to extract the detail you needed>Please see this post hope it helps you and you understand it.
String r = NameArray.columncount("userid", limitstart, loadNumber,loggername);
String temp = r.replaceAll(";\\s", ",").replaceAll("string=", " ")
.replace("anyType{", "").replace(",}", "");
enter code here
check this link for step by step instruction
http://amalan008.blog.com/2013/02/07/how-to-process-an-array-returned-by-a-wsdl-android/

Related

Special character coming parsing the xml

When I am parsing xml, I am getting special in good dynamics application char like that
pic.png
but the actual text is like that "If you've got any question or need"
But when I am parsing same text in normal application its working fine.
I am using sharepoint server to get xml. Now I am using general encoding UTF-8 only.
For parsing I am using XMLpullparser.
So how to resolve special character from xml.
There might be two things you might check:
Persister class used to parse the .xml can be initialised with such constructor:
Persister persister = new Persister(new Format(4, "<?xml version=\"1.0\" encoding= \"UTF-8\" ?>"));
You might replace all such characters while parsing:
value = value.replace("'", "\\'");

I have XML parsing response in Android how do i want to implement JSON parse on that xml response it's possible?

I have XML parsing response in Android ,on that i want to implement JSON parse on that xml response it's possible?
What I understood from your question you want to parse XML to JSON and if that is the case you can use JAVA-JSON library check it out at GITHUB.
Quick example
JSONObject xmlJSONObj = XML.toJSONObject(XML_STRING);
I would suggest you to use json-lib, a library which adds JSON support to any Java program. json-lib can take XML and convert it into a JSON object.
Json-lib
Eg.
String xml = "your xml string";
XMLSerializer xmlSerializer = new XMLSerializer();
JSON json = xmlSerializer.read( xml );

SoapObject Add property xml string in Webservice using ksoap2

I created XML string using XmlSerializer and it prints out as
<tag> string </tag>
I want to add the xml string to SOAPObject and get response from web service.
So I added and when I print out the requestDump the < and > are being replaced by &lt ; and &gt ;
I assume that it is being encoded by HttpTransportSE.
I read here Android Ksoap2 web service for download/Upload and it says I need to convert my string to binary before uploading? I am confused because the API tells us to upload xml. Currently, there is no error or exception but the result is empty. I think it's the encoding problem.
Any help will be appreciated. Thanks!
When using ksoap2 you don't have to handle the serialization yourself. If you want to add an entry to the xml like this:
<tag>string</tag>
Then you just have to call this when constructing the SoapObject you are sending to the server:
soapObject.addProperty("tag", "string");
Also modifying the requestDump is never a good idea. This output is just for debug purposes. That's the reason why you have to set transport.debug = true; for the requestDump or responseDump to even appear. As I said above just use the addProperty() and addSoapObject() methods to construct your request.
Use SoapObject.setInnerText("..."); to add CDATA text to a Ksoap2 request.

JSON parsing in android

I am new to android development,
I want to parse xml i have tried using sax xml parser but as it consist of "&" in it so that URL part is not getting completed parsed.SAX parser parsing upto "&' the rest of the part it is neglacting so i have to use json parser.
But for json parser i need to parse xml into json then from json to string which can be used by the JSON parser.
if any one is having idea wheather it will solve my problem of "&" in xml?
thnx for any help.......
As I see, you want to parse non standard xml. If you can change xml structure, use CDATA for links. If not, you can do some hack, like replace '&' before parsing onto some unique string. And after successful parsing you can replace it back.
DEMO:
String xmlString = "<link>linkwith&</link>"; //some xml with &
xmlString = xmlString.replaceAll("[&]", ".!.!.!.");
XMLHandler xml = new XMLHandler(); //your sax parse handler
xml.parseXML(output); //your parse function
After that, you get your parsed link somehow and make replace back:
String parsedLink = "linkwith.!.!.!.";
parsedLink = parsedLink.replaceAll(".!.!.!.", "&");

Parser issue in android

I am getting the value from a web server. I am getting the value as a string. Can anybody tell me how to convert the string to an xml file and where to store the xml file in android? And how do I access the file to parse the value, can anybody give an example?
Any help would be appreciated
Thanks in advance
In my understanding, Your meaning of "getting the value as string" is parse the content of InputStream. I think you don't have to parse the content and then convert the string to xml file, you can just use FileOuputStream to write the data in InputStream into file system.
You can use SAX or DOM to parse xml, they are both supported by android. See this post for more info.
Just pass the inputstream(response) from webserver to the Dom or Sax Methods no need to convert in to String

Categories

Resources