Reputation: 212
It sounds like a simple question, but I haven't found an answer yet.
I've got an .xml file consists of different items including one URL item. I know the beginning of that URL string item. What is the easiest way to find this URL among other items and get it as a string?
Here is a class which checks if xml file exists. If it exists, I should get an url from it.
public class ConfigFile {
private Context context;
private static String url;
public ConfigFile (Context _context, String _url){
this.context = _context;
this.url = _url;
}
public static String getUrl() {
return url;
}
public static void setUrl(String url) {
ConfigFile.url = url;
}
public void checkExistence(){
File file = new File(context.getApplicationContext().getFilesDir(),"configfile.xml");
if(file.exists()){
// here I should paste code which returns url to set it as connection
//setUrl();
}
else{
//smth
}
}
Upvotes: 0
Views: 1953
Reputation: 5392
Just use basic xml parsing framework built into Android.
Basic Android Documentation on XML parsing. https://developer.android.com/training/basics/network-ops/xml
if you find that one to be too complicated, then use one that is based on annotations. SimpleXML is one I have used in the past and works well.
http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php
Upvotes: 1