Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android XML解析器跳过标记_Android_Xml_Rss - Fatal编程技术网

Android XML解析器跳过标记

Android XML解析器跳过标记,android,xml,rss,Android,Xml,Rss,我正在制作一个可以阅读RSS提要的阅读器。起初我想使用图书馆,但意识到他们无法加载一些数据,所以我决定制作自己的阅读器。但问题是。我的解析器并不总是返回图像,这取决于此RSS的类似站点,而对于类似RSS的站点,在内容中可以找到图像:我在第一次迭代中无法获得数据,因此我让下一个项目获得上一个项目的图像,下面是我的代码字符串title=“” 如何在正确的索引中获取正确的内容:数据?我如何获取您目前使用的库的url?库正在跳过数据,因为它们尚未放置所有键。您必须使用android中带有JSoup的默认

我正在制作一个可以阅读RSS提要的阅读器。起初我想使用图书馆,但意识到他们无法加载一些数据,所以我决定制作自己的阅读器。但问题是。我的解析器并不总是返回图像,这取决于此RSS的类似站点,而对于类似RSS的站点,在内容中可以找到图像:我在第一次迭代中无法获得数据,因此我让下一个项目获得上一个项目的图像,下面是我的代码字符串title=“”


如何在正确的索引中获取正确的
内容:数据
?我如何获取您目前使用的库的url?库正在跳过数据,因为它们尚未放置所有键。您必须使用android中带有JSoup的默认XML解析器手动编辑新标记SAM的库类
    String description = "";
    String link = "";
    String encodedDesciption = "";
    String imgSrc = "image";
    boolean isItem = false;
    try {
        XmlPullParser xmlPullParser = Xml.newPullParser();
        xmlPullParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        xmlPullParser.setInput(inputStream, null);

       // xmlPullParser.nextTag();
        while (xmlPullParser.next() != XmlPullParser.END_DOCUMENT) {

            int eventType = xmlPullParser.getEventType();

            String name = xmlPullParser.getName();
            if(name == null)
                continue;

            if(eventType == XmlPullParser.END_TAG) {
                if(name.equalsIgnoreCase("item")) {
                    isItem = false;
                }
                continue;
            }

            if (eventType == XmlPullParser.START_TAG) {
                if(name.equalsIgnoreCase("item")) {
                    isItem = true;
                    continue;
                }
            }

            String result = "";
            if (xmlPullParser.next() == XmlPullParser.TEXT) {
                result = xmlPullParser.getText();
                xmlPullParser.nextTag();
            }

            if (name.equalsIgnoreCase(TITLE)) {
                title = result;
            } else if (name.equalsIgnoreCase(LINK)) {
                link = result;
            } else if (name.equalsIgnoreCase(DESCRIPTION)) {
                description = result;
            }else if (name.equalsIgnoreCase(DESCRIPTION_ENCODED)) {
                encodedDesciption = result;

            }


            if (title != null && link != null && description != null && imgSrc != null && encodedDesciption != null) {
                if(isItem) {
                    Document document = Jsoup.parse(encodedDesciption);
                    Element img = document.select("img").first();
                    if (img != null) {
                        imgSrc = img.attr("src");
                        Log.d(TAG, "Image found "+imgSrc);
                        img.remove();
                    }else  Log.d(TAG, "Image not found");
                    FeedItem feedItem = new FeedItem(title, description, encodedDesciption, imgSrc, link );
                    feeds.add(feedItem);
                    Log.d(TAG, feedItem.toString());
                }

                title = null;
                link = null;
                description = null;
                isItem = false;
            }


        }


    } catch (XmlPullParserException | IOException e) {
        e.printStackTrace();
    } finally {
        try {
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }