Android make xml node for Soap Parameter - android

a Dot net Webservice is expecting an XML node as a parameter:
The string that it would deserialize to is:
"<Service PTA="" QSF="" xmlns="" />";
I have floundered around trying to make a serializable class with a public string of:
"<Service PTA=\"\" QSF=\"\" xmlns=\"\" />";
But I get errors of 'Cannot Serialize' from:
androidHttpTransport.call(SOAP_ACTION, envelope);
What is the best way to do this?
thanks

Its a Kludge but it works. using KSOAP2 library.
Adding a xml node to SoapObject request, parameter myParam
String xml = "<Service PTA=\"\" QSF=\"\" xmlns=\"\" />";
request.addProperty("myParam>"+xml,"")
Not ideal but...

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("'", "\\'");

Converting JSON Format String to XML String throws an Exception

I am trying for a long time to find a solution about the following problem that I am facing. I get a special json format string from my Database through a Http Request as follows:
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n
<resources>
<string> name=\"Test.Company\">Company</string>\r\n
<string> name=\"Test.Point\">Point</string>\r\n
</resources>"
A format as shown above contains only a string daten type.This format must be used as an XML file for an Android application. The Responed data from server is working properly.
The main point is to convert this special jsonformat to XML.
I am using the following code for convertion to XML as follows:
JSONObject jsonObject = new JSONObject("jsonStr_responded_from_server"); // throws an exception **of type java.lang.String cannot be converted to JSONObject**
String xml = XML.toString(jsonObject);
Did anyone has similar problem???
your server returns the normal string. because json object should be in {your object} format.example json object is {"user":"uservalues","empcode":"emp0041"}. but your string returned from server not in the format it will throws the error. have a look on this link
String xml = jsonStr_responded_from_server;//string xml returns from server. here no need json object

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.

how to get the values from soap response in 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/

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(".!.!.!.", "&");

Categories

Resources