how to get value from xml tag in android



I have made a parser,in that i am getting all the values of that xml tag,But i want to get some values which are inside tag as an argument,I dont know how to get it from tags,The sample xml is as below: sample.xml



<ChargeableRateInfo averageBaseRate="226.7" averageRate="192.69" commissionableUsdTotal="192.69" currencyCode="USD" maxNightlyRate="192.69" nightlyRateTotal="192.69" surchargeTotal="46.8" total="239.49"><NightlyRatesPerRoom size="1"><NightlyRate baseRate="226.7" rate="192.69" promo="true"/></NightlyRatesPerRoom>


,I want to get value of "averageRate","nightlyRateTotal","total",But I have no idea how to get that data?My parser is as below:



while (eventType != XmlPullParser.END_DOCUMENT && !done) {
tagName = parser.getName();

switch (eventType) {
case XmlPullParser.START_DOCUMENT:
break;
case XmlPullParser.START_TAG:
if (tagName.equals(ITEM)) {
rssFeed = new RSSFeed_SelectedHotelResult();

}

if (tagName.equals(DESCRIPTION)) {
name = parser.nextText().toString();
hotel_name_list.add(name);
System.out
.println(":::::::::::::::::DescriptionL:lLLLLLLLLLL"
+ name);
}
if (tagName.equals(OFFER)) {
offer = parser.nextText().toString();
hotel_offer_list.add(offer);
System.out.println(":::::::::::::::::Offer" + offer);
}

if (tagName.equals(HOTEL_IMG)) {
thumbNailUrl = parser.nextText().toString();
hotel_image_list.add(thumbNailUrl);
}
if (tagName.equals(HOTEL_LOCATION)) {
locationDescription = parser.nextText().toString();
hotel_lOCATION_DESC.add(locationDescription);
System.out
.println("::::::::;Location deccription:::::::::::;;"
+ locationDescription);
}

if (tagName.equals(HOTEL_RATE_IMG)) {
tripAdvisorRatingUrl = parser.nextText().toString();
}

if (tagName.equals(HOTEL_PRICE)) {
lowRate = parser.nextText().toString();
}

if (tagName.equals(HOTEL_RATING)) {
hotelRating = parser.nextText().toString();
hotel_rate_list.add(hotelRating);
}

if (tagName.equals(HOTEL_ADDRESS)) {
address1 = parser.nextText().toString();
hotel_address_list.add(address1);
System.out
.println(":::::::::::::hotel address:::::::::::"
+ address1);
}
if (tagName.equals(DESTINATION_ID)) {
destinationId = parser.nextText().toString();
dest_id_list.add(destinationId);
System.out
.println("*********Here Is DestinationID:************"
+ destinationId);
}
if (tagName.equals(CITY)) {
city = parser.nextText().toString();
city_list.add(city);
System.out.println("*********Here Is City:************"
+ city);
}
if (tagName.equals(HOTEL_ID)) {
hotelId = parser.nextText().toString();
hotel_id_list.add(hotelId);
System.out
.println("*********Here Is HotelID:************"
+ hotelId);
}
if (tagName.equals(LATITUDE)) {
latitude = parser.nextText().toString();
latitude_list.add(latitude);
System.out
.println("*********Here Is Latitude:************"
+ hotelId);
}
if (tagName.equals(LONGITUDE)) {
longitude = parser.nextText().toString();
longitude_list.add(longitude);
System.out
.println("*********Here Is Longitude:************"
+ hotelId);
}

break;
case XmlPullParser.END_TAG:
if (tagName.equals(CHANNEL)) {
done = true;
} else if (tagName.equals(ITEM)) {

rssFeed = new RSSFeed_SelectedHotelResult(name,
thumbNailUrl, tripAdvisorRatingUrl,
hotelRating, locationDescription, lowRate,
destinationId, city, hotelId, latitude,
longitude, offer);
rssFeedList.add(rssFeed);

}

break;
}
eventType = parser.next();
}
} catch (Exception e) {
e.printStackTrace();
}

return rssFeedList;

}

No comments:

Post a Comment