Конечный тег ожидается исключение xmlpullparser в Android

Я работаю над парсингом xml, я использую сторонний sml api, но получаю исключение ниже, пожалуйста, помогите мне решить эту проблему, я хочу получитьжурнал"descriptionLong", "RoomAmenity"

04-30 01:17:29.065: W/System.err(2483): org.xmlpull.v1.XmlPullParserException: END_TAG expected (position:START_TAG <description>@1:8021 in java.io.InputStreamReader@52eae5d0) 

мой xml: xml файл здесь

Мой код для разбора, как показано ниже:

public class NewsFeedParser_HotelDesc {

    private InputStream urlStream;
    private XmlPullParserFactory factory;
    private XmlPullParser parser;

    private List<RssFeed_HotelListDesc> rssFeedList;
    private RssFeed_HotelListDesc rssFeed;

    public List<String> hotel_list_data;

    private String urlString;
    private String tagName;

    private String name;
    private String hotelRating;
    private String tripAdvisorReviewCount;
    private String tripAdvisorRatingUrl;
    private String address1;
    private String lowRate;

    private String propertyDescription;
    private String thumbnailUrl;

    private String hotelPolicy;

    private String latitude;
    private String longitude;

    private String checkInTime;
    private String checkOutTime;

    public static final String ITEM = "HotelSummary";
    public static final String CHANNEL = "ns2:HotelInformationResponse";

    public static final String HOTEL_NAME = "name";
    public static final String HOTEL_RATING = "hotelRating";
    public static final String HOTEL_REVIEWS_COUNT = "tripAdvisorReviewCount";
    public static final String HOTEL_RATING_URL = "tripAdvisorRatingUrl";
    public static final String HOTEL_ADDRESS = "address1";
    public static final String HOTEL_PRICE = "lowRate";

    public static final String HOTEL_PROPERTY_DESC = "propertyDescription";
    public static final String HOTEL_IMAGE_GALLARY = "thumbnailUrl";

    public static final String HOTEL_POLICY = "hotelPolicy";

    public static final String LATITUDE = "latitude";
    public static final String LONGITUDE = "longitude";

    public static final String CHECK_IN = "checkInTime";
    public static final String CHECK_OUT = "checkOutTime";

    // new attribute added...!!
    public static final String ROOM_TYPE = "RoomType";
    public static String ROOM_CODE = "room_code";
    public static final String DESCRIPTIONLONG = "descriptionLong";
    public static final String ROOMAMENITY = "RoomAmenity";
    public static final String AMENITY = "amenity";

    private String description_long;
    private String food_drink;
    private String bathrum;
    private String rum_code;
    private String amenity;

    public NewsFeedParser_HotelDesc(String urlString) {
        this.urlString = urlString;
    }

    public NewsFeedParser_HotelDesc() {
        // TODO Auto-generated constructor stub
    }

    public static InputStream downloadUrl(String urlString) throws IOException {
        URL url = new URL(urlString);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setDoInput(true);
        // conn.setDoOutput(true);

        conn.setRequestProperty("Accept",
                "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
        conn.setRequestProperty("Accept-Language", "en-us,en;q=0.5");
        conn.setRequestProperty("Accept-Charset",
                "ISO-8859-1,utf-8;q=0.7,*;q=0.7");

        conn.connect();

        int rCode = conn.getResponseCode();

        System.out.println("************Responce Code:************" + rCode);

        InputStream stream = conn.getInputStream();

        if (conn.getResponseCode() != 200) {
            stream = conn.getErrorStream();
            System.out.println("**********************OK**************");
        } else {
            stream = conn.getInputStream();
        }

        return stream;
    }

    public List<RssFeed_HotelListDesc> parse() {
        try {
            int count = 0;
            factory = XmlPullParserFactory.newInstance();
            parser = factory.newPullParser();
            urlStream = downloadUrl(urlString);
            parser.setInput(urlStream, null);
            int eventType = parser.getEventType();
            boolean done = false;
            rssFeed = new RssFeed_HotelListDesc();

            hotel_list_data = new ArrayList<String>();

            rssFeedList = new ArrayList<RssFeed_HotelListDesc>();
            while (eventType != XmlPullParser.END_DOCUMENT && !done) {
                tagName = parser.getName();
                // System.out.println("City Tag:"+tagName);
                switch (eventType) {
                case XmlPullParser.START_DOCUMENT:
                    break;
                case XmlPullParser.START_TAG:
                    if (tagName.equals(ITEM)) {
                        rssFeed = new RssFeed_HotelListDesc();

                    }

                    if (tagName.equals(HOTEL_NAME)) {
                        name = parser.nextText().toString();

                        hotel_list_data.add(name);
                    }
                                        if (tagName.equalsIgnoreCase(ROOM_TYPE)) {
                        description_long = parser.nextText().toString();

                        System.out
                                .println("==============description long==============="
                                        + description_long);

                        hotel_list_data.add(description_long);
                    }

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

                        rssFeed = new RssFeed_HotelListDesc(name, hotelRating,
                                tripAdvisorRatingUrl, address1, lowRate,
                                propertyDescription, thumbnailUrl, hotelPolicy,
                                latitude, longitude, checkInTime, checkOutTime);

                        rssFeedList.add(rssFeed);

                    }

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

        return rssFeedList;

    }
}

0 ответов

Другие вопросы по тегам