Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.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
Java 使用Atom阅读器阅读困难_Java_Android_Parsing_Feed_Atom Feed - Fatal编程技术网

Java 使用Atom阅读器阅读困难

Java 使用Atom阅读器阅读困难,java,android,parsing,feed,atom-feed,Java,Android,Parsing,Feed,Atom Feed,我尝试为RSS和Atom制作一个解析器,其中RSS提要显示标题,而Atom显示图像和描述加链接。我的解析器似乎只适用于RSS。你能告诉我为什么吗?勾选这个: public void Get_Parse_Feed(String URL_link, Input_Streamer_Class is, List<String> headlines, List<String> links) { try { // URL is = ne

我尝试为RSS和Atom制作一个解析器,其中RSS提要显示标题,而Atom显示图像和描述加链接。我的解析器似乎只适用于RSS。你能告诉我为什么吗?勾选这个:

public void Get_Parse_Feed(String URL_link, Input_Streamer_Class is, List<String> headlines, List<String> links)
{
    try
    {
        // URL
        is = new Input_Streamer_Class();

        /*
         * 
         *             Reserved URLS:
         *             --> http://feeds.pcworld.com/pcworld/latestnews
         *             --> http://feeds2.feedburner.com/boy-kuripot
         *             --> http://feeds2.feedburner.com/phcreditcardpromos
         *             --> http://feeds.feedburner.com/blogspot/MKuf
         *             --> http://googleblog.blogspot.com/atom.xml
         * 
         */

        is.Set_URL(URL_link);

        // Set XML pull factory.
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(false);
        XmlPullParser xpp = factory.newPullParser();

        // Picking up input stream...
        xpp.setInput(is.Get_Input_Stream(is.Get_URL()), "UTF_8");

        // Check for inside item.
        boolean insideItem = false;

        // Pick event type. (START_TAG, END_TAG, etc.)
        int eventType = xpp.getEventType();
        while(eventType != XmlPullParser.END_DOCUMENT)
        {
            if(eventType == XmlPullParser.START_TAG)
            {
                if(xpp.getName().equalsIgnoreCase("item"))
                {
                    insideItem = true;

                } else if(xpp.getName().equalsIgnoreCase("title")) {

                    if(insideItem)
                    {
                        headlines.add(xpp.nextText()); // --> Extract the headline.
                    }

                } else if(xpp.getName().equalsIgnoreCase("link")) {

                    if(insideItem)
                    {
                        links.add(xpp.nextText()); // --> Extract the link of article.
                    }

                }

            } else if((eventType == XmlPullParser.END_TAG) && xpp.getName().equalsIgnoreCase("item")) {

                insideItem = false;

            }

            eventType = xpp.next(); // --> Move to the next element.
        }

    } catch(MalformedURLException e) {

        e.printStackTrace();

    } catch(XmlPullParserException e) {

        e.printStackTrace();

    } catch(IOException e) {

        e.printStackTrace();

    }
}
public void Get\u Parse\u Feed(字符串URL\u链接、输入流\u类、列表标题、列表链接)
{
尝试
{
//网址
is=新输入\拖缆\类();
/*
* 
*保留URL:
*             --> http://feeds.pcworld.com/pcworld/latestnews
*             --> http://feeds2.feedburner.com/boy-kuripot
*             --> http://feeds2.feedburner.com/phcreditcardpromos
*             --> http://feeds.feedburner.com/blogspot/MKuf
*             --> http://googleblog.blogspot.com/atom.xml
* 
*/
设置URL(URL链接);
//设置XML拉工厂。
XmlPullParserFactory工厂=XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xpp=factory.newPullParser();
//正在提取输入流。。。
setInput(is.Get_Input_Stream(is.Get_URL()),“UTF_8”);
//检查内部物品。
布尔值insideItem=false;
//选择事件类型。(开始标记、结束标记等)
int eventType=xpp.getEventType();
while(eventType!=XmlPullParser.END_文档)
{
if(eventType==XmlPullParser.START_标记)
{
if(xpp.getName().equalsIgnoreCase(“项”))
{
insideItem=真;
}else if(xpp.getName().equalsIgnoreCase(“title”)){
如果(内部项目)
{
headlines.add(xpp.nextText());//-->提取标题。
}
}else if(xpp.getName().equalsIgnoreCase(“链接”)){
如果(内部项目)
{
links.add(xpp.nextText());//-->提取文章的链接。
}
}
}else if((eventType==XmlPullParser.END_标记)和&xpp.getName().equalsIgnoreCase(“项”)){
insideItem=假;
}
eventType=xpp.next();//-->移动到下一个元素。
}
}捕获(格式错误){
e、 printStackTrace();
}catch(XMLPullParseRexE){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
}

每次我发现这篇教程加上我自己的MVC管理,结果都令人印象深刻。但是,当我尝试实现一个包含Atom提要的URL时,它没有出现。

很明显,结构不同,您需要两个不同的解析器!或者2个装在一个里面(不知道这会有多大帮助)

因为:

RSS 2.0:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
        <channel>

                <title>Example Feed</title>
                <description>Insert witty or insightful remark here</description>
                <link>http://example.org/</link>
                <lastBuildDate>Sat, 13 Dec 2003 18:30:02 GMT</lastBuildDate>
                <managingEditor>johndoe@example.com (John Doe)</managingEditor>

                <item>
                        <title>Atom-Powered Robots Run Amok</title>
                        <link>http://example.org/2003/12/13/atom03</link>
                        <guid isPermaLink="false">urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</guid>
                        <pubDate>Sat, 13 Dec 2003 18:30:02 GMT</pubDate>
                        <description>Some text.</description>
                </item>

        </channel>
</rss>

示例提要
在此处插入诙谐或有见地的评论
http://example.org/
2003年12月13日星期六18:30:02格林尼治标准时间
johndoe@example.com(无名氏)
原子能机器人疯狂运行
http://example.org/2003/12/13/atom03
urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a
2003年12月13日星期六18:30:02格林尼治标准时间
一些文本。
Atom 1.0:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

        <title>Example Feed</title>
        <subtitle>Insert witty or insightful remark here</subtitle>
        <link href="http://example.org/"/>
        <updated>2003-12-13T18:30:02Z</updated>
        <author>
                <name>John Doe</name>
                <email>johndoe@example.com</email>
        </author>
        <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>

        <entry>
                <title>Atom-Powered Robots Run Amok</title>
                <link href="http://example.org/2003/12/13/atom03"/>
                <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
                <updated>2003-12-13T18:30:02Z</updated>
                <summary>Some text.</summary>
        </entry>

</feed>

示例提要
在此处插入诙谐或有见地的评论
2003-12-13T18:30:02Z

,代码中的不同问题是,在atom上,您有
条目
而不是像rss中那样的
条目

但是,这两个代码在包含提要的HTML网站中使用:RSS或Atom。如果我对你的答案的第一个评论是错误的,你把它们放在哪里?在res文件夹下的布局文件夹中?如何连接或如何工作?嗯…我明白了。您可以将行
if(xpp.getName().equalsIgnoreCase(“项”)
更改为
if(xpp.getName().equalsIgnoreCase(“项”)| | xpp.getName().equalsIgnoreCase(“项”))
但是如果你想解析更多的元素,最好考虑一种更复杂、更安全的方法。我正在使用这个包含Atom提要的URL,
http://googleblog.blogspot.com/atom.xml
,但它仍然没有显示。我是否获得了包含Atom提要的正确URL?