Skip to content

Instantly share code, notes, and snippets.

@hwrdprkns
Created March 25, 2011 01:57
Show Gist options
  • Save hwrdprkns/886231 to your computer and use it in GitHub Desktop.
Save hwrdprkns/886231 to your computer and use it in GitHub Desktop.
MyLovleyXMLParser
public URLRead(URL url) {
BufferedReader reader;
awl = new ArrayList<AptWrapper>();
Log.d(TAG,url.toExternalForm());
try {
reader = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
boolean flag = false;
error_flag = false;
while ((str = reader.readLine()) != null && error_flag == false) {
str = str.trim();
if (str.equals("<searchTitle>")) {
str = reader.readLine();
ResultView.rv.setTotalText(str.trim());
}
if (str.equals("</listing>")) {
AptWrapper aw = new AptWrapper();
aw.listingID = listingID;
aw.listingURL = listingURL;
aw.city = city;
aw.lat = lat;
aw.lon = lon;
aw.address = address;
aw.tag = tag;
aw.thumb = thumb;
aw.desc = desc;
aw.image = image;
aw.feature = feature;
aw.bed = bed;
aw.bath = bath;
aw.price = price;
aw.summary = summary;
aw.agent = agent;
aw.phone = phone;
aw.email = email;
aw.company = company;
aw.companyAdd = companyAdd;
aw.companyCSZ = companyCSZ;
aw.companyPhone = companyPhone;
aw.avail = avail;
awl.add(aw);
flag = false;
}
if (flag) {
// Log.d("Priv","Flag Inner");
if (str.equals("<listingID>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
try {
listingID = Integer.parseInt(str);
} catch (Exception e) {
error_flag = true;
// Log.d("Priv","Listing ID Error");
}
} else if (str.equals("<listingURL>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
listingURL = str;
} else if (str.equals("<city>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
city = str;
} else if (str.equals("<latitude>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
try {
lat = Double.parseDouble(str);
} catch (Exception e) {
error_flag = true;
}
} else if (str.equals("<longitude>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
try {
lon = Double.parseDouble(str);
} catch (Exception e) {
error_flag = true;
}
} else if (str.equals("<address>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
address = str;
} else if (str.equals("<tagline>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
tag = str;
} else if (str.equals("<thumbnail>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
thumb = str;
} else if (str.equals("<description>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
desc = str;
} else if (str.equals("<images>")) {
try {
str = reader.readLine();
str = str.trim();
str = convert(str);
image = str;
} catch (Exception e) {
error_flag = true;
}
} else if (str.equals("<features>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
str = str.substring(0, str.indexOf("<"));
str.trim();
feature = str;
} else if (str.equals("<bedrooms>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
try {
bed = Integer.parseInt(str);
} catch (Exception e) {
bed = 0;
}
} else if (str.equals("<bathrooms>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
try {
bath = Integer.parseInt(str);
} catch (Exception e) {
bath = 0;
}
} else if (str.equals("<price>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
price = str;
} else if (str.equals("<availability>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
avail = str;
} else if (str.equals("<summary>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
summary = str;
} else if (str.equals("<agentName>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
agent = str;
} else if (str.equals("<agentPhone>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
phone = str;
} else if (str.equals("<agentEmail>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
email = str;
} else if (str.equals("<agentCompanyName>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
company = str;
} else if (str.equals("<agentCompanyStreetAddress>")) {
str = reader.readLine();
str = convert(str);
companyAdd = str;
} else if (str.equals("<agentCompanyCityStateZip>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
companyCSZ = str;
} else if (str.equals("<agentCompanyPhone>")) {
str = reader.readLine();
str = str.trim();
str = convert(str);
companyPhone = str;
}
// output+=convert(inputLine)+"\n";
}
if (str.equals("<listing>")) {
flag = true;
}
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
if (error_flag == true) {
awl = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment