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
Related
I want to create a JSON file to style my google map but I get this message: E/Google Maps Android API: Map style parsing failed: org.json.JSONException: Value res of type java.lang.String cannot be converted to JSONArray
E/MapsActivityRaw: Style parsing failed. Any help?
Here is my code example where I have the method with JSON creation and on left side you see the raw package where the JSON file
Here is the error that I get
I used Google platform mapstyle.withgoogle.com. But the thing that I'm not sure about, that I created a Text Document then changed the ending to .json, copied the JSON code from google platform and put it there and then copied the file and put it in android studio. Because I couldn't know how to create a JSON file in android studio. I don't know if it sounds the right way to do that?
in the previous comment that I left you, it was because I did not have the solution, but in reviewing the google documentation well I realized that there are two types of codes to implement the styles, one by JSON files and others by means of string
For the code that you show in the image it has to have a style_gray string resource, for this case I would suppose that you would have an xml file or that variable in the string.xml, you could use that same code like this:
googleMap.setMapStyle(new MapStyleOptions(getResources().getString(R.raw.map_style_aubergine)));
For that error to be solved, you would have to implement this other code, which if it is compatible with JSON files in the format generated by https://mapstyle.withgoogle.com/, the code would be the following:
googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this,R.raw.map_style_aubergine));
In my case the map_style_aubergine is the JSON file and a variable in the string.xml you can use this as an example and make the respective corrections in your code
I have tried one xml string response using SAX parser. I am receiving the tag names only in Logs: OtpResponse, return, Resp, TssId, etc....
I want the tag outputs only.. and am getting tag names only..
My Sample Program :
My Sample XML Format :
http://textuploader.com/5ezjf
Appreciate, if the above xml format processing sample program suggest.
Anyone help to get solution..
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/
Hi I have created xml where i need to pass file name and sent to server. It is working fine. But when the file name contains special character the name looks different in xml. similarly in reading same problem occurred. eg if file name is ♥♣◘• then i cant send the exact in xml also i cant read as it is from xml. How to resolve this type of issue. Whether i need to set any parameters in xml?
Thanks
Sunil Kumar Sahoo
Seems you have en ENCODING problem... Try out a few like UTF16 or UTF32... I know there are some issues in Android 'bout encoding stuff, you never really know what you get except if you FORCE it !
Try then using stuffs like :
String(byte[] data, String charsetName)
Converts the byte array to a string using the named charset.
with charsetname such as "UTF-8" or "UTF-16".
I have an XML file which I have retrieved the data via a Document variable. I need to extract data for a class which contains several fields. What is the easiest way to retrieve the records from the Document variable ?
For Document objet use DOM parser.
For XML files use SAX parser.
Try to use a SAX parser for XML parsing, because it is more memory efficient.