ParseXml 在某些提要 xml 上失​​败

如何解决ParseXml 在某些提要 xml 上失​​败

制作一个简单的RSS提要阅读器,用户可以从固定站点列表中进行选择。它适用于 20 个提要,但在其他 15 个提要中失败(都是 35 个有效的 xml 和无效的 xsd)。应用不会崩溃,logcat 没有错误,只有警告。

一些对我来说效果很好的提要是:

一些对我来说不起作用的提要:

DOM解析器

import android.annotation.SuppressLint;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

public class DOMParser {

    private RSSFeed _feed = new RSSFeed();

    public RSSFeed parseXml(String xml) {

        try {
            // Create required instances
            DocumentBuilderFactory dbf;
            dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();

            // Parse the xml
            Document doc = db.parse(xml);
            doc.getDocumentElement().normalize();

            NodeList nl = doc.getElementsByTagName("item");
            int length = nl.getLength();

            for (int i = 0; i < length; i++) {

                RSSItem _item = new RSSItem();

                if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) {

                        Element eElement = (Element) nl.item(i);

                        //Get Link
                        _item.setLink(eElement.getElementsByTagName("link").item(0).getTextContent());

                        //Get Date
                        //Taking pubDate and make it HH:mm dd/MM/yy
                        String TimeDate = eElement.getElementsByTagName("pubDate").item(0).getTextContent();
                        String ZYear = TimeDate.substring(12,16),ZMonth = TimeDate.substring(8,11),ZDay = TimeDate.substring(5,7);
                        String ZHour = TimeDate.substring(17,19),ZMinute = TimeDate.substring(20,22);
                        String ZTimezone = TimeDate.substring(26,30);

                        if (ZMonth.equals("Jar")) {
                            ZMonth = "01";
                        } else if (ZMonth.equals("Feb")) {
                            ZMonth = "02";
                        } else if (ZMonth.equals("Mar")) {
                            ZMonth = "03";
                        } else if (ZMonth.equals("Apr")) {
                            ZMonth = "04";
                        } else if (ZMonth.equals("May")) {
                            ZMonth = "05";
                        } else if (ZMonth.equals("Jun")) {
                            ZMonth = "06";
                        } else if (ZMonth.equals("Jul")) {
                            ZMonth = "07";
                        } else if (ZMonth.equals("Aug")) {
                            ZMonth = "08";
                        } else if (ZMonth.equals("Sep")) {
                            ZMonth = "09";
                        } else if (ZMonth.equals("Oct")) {
                            ZMonth = "10";
                        } else if (ZMonth.equals("Nov")) {
                            ZMonth = "11";
                        } else if (ZMonth.equals("Dec")) {
                            ZMonth = "12";
                        }

                        TimeDate = ZHour + ":" + ZMinute + " " + ZDay + "/" + ZMonth + "/" + ZYear;

                        //Convert date to milliseconds since 00:00 01/01/1970
                        @SuppressLint("SimpleDateFormat") SimpleDateFormat formatter = new SimpleDateFormat("HH:mm dd/MM/yyyy");
                        formatter.setLenient(false);
                        Date date_before = formatter.parse(TimeDate);
                        assert date_before != null;
                        long milliseconds = date_before.getTime();

                        //Add time to reach +0200 Athens/Greece
                        if (ZTimezone.equals("0000")) {
                            milliseconds = milliseconds + 7200000;
                        }

                        _item.setDateComparison((int) milliseconds);

                        // add item to the list
                        _feed.addItem(_item);
                    }
                }
            } catch (ParserConfigurationException | IOException | ParseException | SAXException e) {
            e.printStackTrace();
        }
        // Return the final feed once all the Items are added to the RSSFeed
        // Object(_feed).
        return _feed;

    }

}

logcat 警告

2020-12-28 23:26:34.305 30015-30071/ozma13.riseapp W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
2020-12-28 23:26:34.423 30015-30071/ozma13.riseapp W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
2020-12-28 23:26:34.530 30015-30071/ozma13.riseapp W/System.err: org.xml.sax.SAXParseException: Unexpected end of document
2020-12-28 23:26:34.533 30015-30071/ozma13.riseapp W/System.err:     at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:125)
2020-12-28 23:26:34.534 30015-30071/ozma13.riseapp W/System.err:     at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:155)
2020-12-28 23:26:34.534 30015-30071/ozma13.riseapp W/System.err:     at ozma13.riseapp.DOMParser.parseXml(DOMParser.java:30)
2020-12-28 23:26:34.534 30015-30071/ozma13.riseapp W/System.err:     at ozma13.riseapp.MainActivity$AsyncLoadXMLFeed.doInBackground(MainActivity.java:532)
2020-12-28 23:26:34.534 30015-30071/ozma13.riseapp W/System.err:     at ozma13.riseapp.MainActivity$AsyncLoadXMLFeed.doInBackground(MainActivity.java:441)
2020-12-28 23:26:34.535 30015-30071/ozma13.riseapp W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:333)
2020-12-28 23:26:34.535 30015-30071/ozma13.riseapp W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2020-12-28 23:26:34.535 30015-30071/ozma13.riseapp W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
2020-12-28 23:26:34.535 30015-30071/ozma13.riseapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
2020-12-28 23:26:34.536 30015-30071/ozma13.riseapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
2020-12-28 23:26:34.536 30015-30071/ozma13.riseapp W/System.err:     at java.lang.Thread.run(Thread.java:780)
2020-12-28 23:26:35.120 30015-30043/ozma13.riseapp W/ThreadedRenderer: ThreadedRenderer::detachAnimators pid = 30015 threadid = 30043
2020-12-28 23:26:35.183 30015-30043/ozma13.riseapp W/ThreadedRenderer: ThreadedRenderer::detachAnimators pid = 30015 threadid = 30043
2020-12-28 23:26:37.734 30015-30043/ozma13.riseapp W/ThreadedRenderer: ThreadedRenderer::detachAnimators pid = 30015 threadid = 30043

解决方法

答案是在非检索 xml 中的“https”和“http”之间切换。我不知道为什么,但这对我来说就是解决办法!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-