xml Parsinmg错误:08-31 17:20:29.324:E /错误:(12343):java.io.InputStreamReader中未终止的实体引用

时间:2014-08-31 11:25:28

标签: android xml parsing

我的xml以下。

<?xml version="1.0"?>
<indvideo>
    <video id="257">
        <caption>মগবাজারে তিন খুন</caption>
        <link>https://www.youtube.com/watch?v=HbZXd2fAKmU&list=UUATUkaOHwO9EP_W87zCiPbA</link>
        <date>2014-08-29</date>
        <videoimage>http://independent24.tv/video_image/</videoimage>
    </video>
    <video id="255">
        <caption>আজকের বাংলাদেশ</caption>
        <link>https://www.youtube.com/watch?v=xWjZ-L_rXEo</link>
        <date>2014-08-19</date>
        <videoimage>http://independent24.tv/video_image/</videoimage>
    </video>
    <video id="256">
        <caption>বেকার তোবার শ্রমিকেরা</caption>
        <link>https://www.youtube.com/watch?v=VBftAHa4bkE</link>
        <date>2014-08-19</date>
        <videoimage>http://independent24.tv/video_image/</videoimage>
    </video>
    <video id="252">
        <caption>২০ দলের সমাবেশ</caption>
        <link>https://www.youtube.com/watch?v=5c-QSqQjSBc</link>
        <date>2014-08-18</date>
        <videoimage>http://independent24.tv/video_image/</videoimage>
    </video>
    <video id="253">
        <caption>আজকের বাংলাদেশ</caption>
        <link>https://www.youtube.com/watch?v=6ARoX4xmzM8</link>
        <date>2014-08-18</date>
        <videoimage>http://independent24.tv/video_image/</videoimage>
    </video>
    <video id="254">
        <caption>খাতুনগঞ্জ থেকে মতিঝিল</caption>
        <link>https://www.youtube.com/watch?v=W-YSKD44fiQ</link>
        <date>2014-08-18</date>
        <videoimage>http://independent24.tv/video_image/</videoimage>
    </video>
    <video id="251">
        <caption>বিচারপতিদের অভিশংসন ক্ষমতা</caption>
        <link>https://www.youtube.com/watch?v=DMaiyPxcyrI</link>
        <date>2014-08-16</date>
        <videoimage>http://independent24.tv/video_image/</videoimage>
    </video>
    <video id="250">
        <caption>পালিত হচ্ছে শোক দিবস</caption>
        <link>https://www.youtube.com/watch?v=9sHuof68uVA</link>
        <date>2014-08-15</date>
        <videoimage>http://independent24.tv/video_image/</videoimage>
    </video>
    <video id="246">
        <caption>আজকের বাংলাদেশ</caption>
        <link>https://www.youtube.com/watch?v=DPbVNRiKXfs</link>
        <date>2014-08-12</date>
        <videoimage>http://independent24.tv/video_image/</videoimage>
    </video>
    <video id="247">
        <caption>জ্বালানি তেলের দাম </caption>
        <link>https://www.youtube.com/watch?v=EiwJSS5HE3c</link>
        <date>2014-08-12</date>
        <videoimage>http://independent24.tv/video_image/</videoimage>
    </video>
</indvideo>

当我用下面的代码解析它时

public ArrayList<NewsItem> getVideoListFromXML(String url) {

    ArrayList<NewsItem> newsItemList = new ArrayList<NewsItem>();

    XMLParser parser = new XMLParser();
    String xml = parser.getXmlFromUrl(url, ""); // getting XML
    Document doc = parser.getDomElement(xml); // getting DOM
    Log.e("xml:", "" + xml);

    NodeList nodeList = doc.getElementsByTagName(KEY_VIDEO_ITEM);

    Log.e("Node Length():-----", "" + nodeList.getLength());

    for (int i = 0; i < nodeList.getLength(); i++) {

        Element e = (Element) nodeList.item(i);

        NewsItem aNews = new NewsItem();

        String news_Title = parser.getValue(e, NODE_VIDEO_TITLE);
        aNews.setNews_Title(news_Title);

        String video_link = parser.getValue(e, NODE_VIDEO_LINK);
        aNews.setVideo_Link(video_link);

        String video_date = parser.getValue(e, NODE_VIDEO_DATE);
        aNews.setDate(video_date);

        Log.e("NODE_VIDEO_TITLE", "" + aNews.getNews_Title());
        Log.e("NODE_VIDEO_LINK", "" + aNews.getVideo_Link());
        Log.e("NODE_VIDEO_DATE", "" + aNews.getDate());

        newsItemList.add(aNews);

    }

    return newsItemList;
}

我的解析错误如下:

08-31 17:20:29.324: E/Error:(12343): unterminated entity ref (position:ENTITY_REF @3:108 in java.io.InputStreamReader@444ccbf0) 

1 个答案:

答案 0 :(得分:0)

你需要更换所有&amp;与&amp;放大器;

XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(url, "");

xml=xml.replaceAll("&","&amp;");
xml= xml.replaceAll("?","&#63;");

由于