Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.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/2/ionic-framework/2.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 RSS阅读器中的描述节点问题获取数据_Android_Xml Parsing_Rss Reader_Android Parser - Fatal编程技术网

从Android RSS阅读器中的描述节点问题获取数据

从Android RSS阅读器中的描述节点问题获取数据,android,xml-parsing,rss-reader,android-parser,Android,Xml Parsing,Rss Reader,Android Parser,我一直在开发一个Android RSS阅读器应用程序,在从描述节点获取HTML内容时遇到问题 我试图从以下XML获取数据 <description> <p><a href="http://in.news.yahoo.com/search-arizona-girl-6-turns-back-her-tucson-021230195.html"> <img src="http://l.yimg.com/bt/api/res/1.

我一直在开发一个Android RSS阅读器应用程序,在从描述节点获取HTML内容时遇到问题

我试图从以下XML获取数据

        <description>
    <p><a href="http://in.news.yahoo.com/search-arizona-girl-6-turns-back-her-tucson-021230195.html">
   <img src="http://l.yimg.com/bt/api/res/1.2/t8X__zdk6shihpWw0Nenfw--/YXBwaWQ9eW5ld3M7Zmk9ZmlsbDtoPTg2O3B4b2ZmPTUwO3B5b2ZmPTA7cT04NTt3PTEzMA--/http://media.zenfs.com/en_us/News/Reuters/2012-04-24T021230Z_1_CDEE83N064W00_RTROPTP_2_USA-MISSING-ARIZONA.JPG" 
width="130" height="86" alt="Handout photo of Isabel Mercedes Celis" align="left" title="Handout photo of Isabel Mercedes Celis" border="0" />

</a>
      TUCSON, Arizona (Reuters) - The search for a missing 6-year-old Arizona girl who a               authorities said may have been snatched from her bedroom in Tucson entered its third day on  Monday as search dogs shifted investigators' attention back to the child's home. The  parents of first-grader Isabel Mercedes Celis told detectives she was last seen on Friday  night when they tucked her into bed, and was found to have vanished when a family member   entered her room the next morning to awaken her, police said. ...
    </p>
  <br clear="all"/>
 </description>

如果描述节点包含HTML标记,则它不包含任何文本\节点类型的子节点,这就是它返回空的原因

检查“描述”节点中的子节点的类型,以了解如何处理这些子节点

编辑 一种解决方案是使用getTextContent()而不是搜索文本节点。而不是:

if (elem.hasChildNodes()) {
    for (child = elem.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() == Node.TEXT_NODE) {
            return child.getNodeValue();
        }
    }
}
你只需去:

return elem.getTextContent();
稍后,您可以使用
HTML.fromHtml()
解析HTML:

(见附件)

编辑2 替换

ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

如果描述节点包含HTML标记,则它不包含任何文本\节点类型的子节点,这就是它返回空的原因

检查“描述”节点中的子节点的类型,以了解如何处理这些子节点

编辑 一种解决方案是使用getTextContent()而不是搜索文本节点。而不是:

if (elem.hasChildNodes()) {
    for (child = elem.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() == Node.TEXT_NODE) {
            return child.getNodeValue();
        }
    }
}
你只需去:

return elem.getTextContent();
稍后,您可以使用
HTML.fromHtml()
解析HTML:

(见附件)

编辑2 替换

ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

检查这个例子。它是一个简单的RSS阅读器,非常容易理解

看看这个例子。它是一个简单的RSS阅读器,非常容易理解

在android中显示HTML内容的最佳方式是使用Webview。因此,使用Webview显示描述节点内的数据。它将同时显示文本和图像。以下是示例代码

    WebView Description;
    Description = (WebView)findViewById(R.id.webView1);
    Description.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    Description.getSettings().setJavaScriptEnabled(true);
    Description.getSettings().setBuiltInZoomControls(true);





    Bundle mybundle = getIntent().getExtras();
    Integer NewsNumber = mybundle.getInt("number");

    final String CurrentTitle = Arrays.Title[NewsNumber];
    String CurrentDescription = Arrays.Description[NewsNumber];


    NewsTitle.setText(CurrentTitle);

    Description.loadDataWithBaseURL (null, "<html>"+CurrentDescription+"</html>", "text/html", "UTF-8",
    null); 
WebView描述;
Description=(WebView)findviewbyd(R.id.WebView 1);
Description.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_列);
Description.getSettings().setJavaScriptEnabled(true);
Description.getSettings().SetBuilTinZoomControl(true);
Bundle mybundle=getIntent().getExtras();
整数NewsNumber=mybundle.getInt(“数字”);
最后一个字符串CurrentTitle=Arrays.Title[NewsNumber];
字符串CurrentDescription=Arrays.Description[NewsNumber];
newsttitle.setText(CurrentTitle);
Description.loadDataWithBaseURL(null、“+CurrentDescription+”、“text/html”、“UTF-8”,
无效);

在android中显示HTML内容的最佳方法是使用Webview。因此,使用Webview显示描述节点内的数据。它将同时显示文本和图像。以下是示例代码

    WebView Description;
    Description = (WebView)findViewById(R.id.webView1);
    Description.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    Description.getSettings().setJavaScriptEnabled(true);
    Description.getSettings().setBuiltInZoomControls(true);





    Bundle mybundle = getIntent().getExtras();
    Integer NewsNumber = mybundle.getInt("number");

    final String CurrentTitle = Arrays.Title[NewsNumber];
    String CurrentDescription = Arrays.Description[NewsNumber];


    NewsTitle.setText(CurrentTitle);

    Description.loadDataWithBaseURL (null, "<html>"+CurrentDescription+"</html>", "text/html", "UTF-8",
    null); 
WebView描述;
Description=(WebView)findviewbyd(R.id.WebView 1);
Description.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_列);
Description.getSettings().setJavaScriptEnabled(true);
Description.getSettings().SetBuilTinZoomControl(true);
Bundle mybundle=getIntent().getExtras();
整数NewsNumber=mybundle.getInt(“数字”);
最后一个字符串CurrentTitle=Arrays.Title[NewsNumber];
字符串CurrentDescription=Arrays.Description[NewsNumber];
newsttitle.setText(CurrentTitle);
Description.loadDataWithBaseURL(null、“+CurrentDescription+”、“text/html”、“UTF-8”,
无效);

是的..我会试试。任何例子或参考都是值得欣赏的;这里我使用的是HashMap类型的字符串。所以可能是因为我的代码中没有得到描述标签。。为什么我错了??请指导我…在您的代码中,搜索
child.getNodeType()==Node.TEXT\u Node
。如果描述为HTML,则描述中没有此类节点。有一个
p
节点。我将更新我的答案以添加leadsThanks以更新答案,但仍面临错误类型ArrayList中的方法add(HashMap)不适用于参数(HashMap),希望您给出我的答案。我接受你的回复。非常感谢你编辑代码。我发现在获取数据时,我没有收到HTML格式的代码。那么问题在哪里呢?你明白我的意思了吗?是的。我会试试。任何例子或参考资料都是值得欣赏的;这里我使用的是HashMap类型的字符串。所以可能是因为我的代码中没有得到描述标签。。为什么我错了??请指导我…在您的代码中,搜索
child.getNodeType()==Node.TEXT\u Node
。如果描述为HTML,则描述中没有此类节点。有一个
p
节点。我将更新我的答案以添加leadsThanks以更新答案,但仍面临错误类型ArrayList中的方法add(HashMap)不适用于参数(HashMap),希望您给出我的答案。我接受你的回复。非常感谢你编辑代码。我发现在获取数据时,我没有收到HTML格式的代码。那么问题在哪里呢?你明白我的意思了吗?谢谢你帮助我给出代码来显示html标记的数据。但我在这之前是结构化的。若你们运行我的代码,你们会发现在标签里我并没有得到任何地方的描述。所以这是HashMap的二重唱或者其他的什么..k,告诉我你想要实现什么?是否要列出“描述”节点中的数据?我认为您应该列出RSS标题及其图像,当我们单击任何标题时,说明数据应该显示在网络视图中。这是我创建RSS阅读器的方式,它工作得非常好。感谢您帮助我提供显示html标记数据的代码。但我在这之前是结构化的。若你们运行我的代码,你们会发现在标签里我并没有得到任何地方的描述。所以这是HashMap的二重唱或者其他的什么..k,告诉我你想要实现什么?你想列出描述节点中的数据吗?我认为你应该列出RSS标题及其图像,当我们点击任何标题时,描述数据应该显示在网络视图中。这是我创建RSS阅读器的方式,它工作得非常好。
SimpleAdapter adapter = new SimpleAdapter(...);
adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
    public boolean setViewValue(View view, Object data, String textRepresentation) {
        if (data instanceof Spanned && view instanceof TextView) {
            ((TextView) view).setText((Spanned) data));
        }
    }
}
    WebView Description;
    Description = (WebView)findViewById(R.id.webView1);
    Description.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    Description.getSettings().setJavaScriptEnabled(true);
    Description.getSettings().setBuiltInZoomControls(true);





    Bundle mybundle = getIntent().getExtras();
    Integer NewsNumber = mybundle.getInt("number");

    final String CurrentTitle = Arrays.Title[NewsNumber];
    String CurrentDescription = Arrays.Description[NewsNumber];


    NewsTitle.setText(CurrentTitle);

    Description.loadDataWithBaseURL (null, "<html>"+CurrentDescription+"</html>", "text/html", "UTF-8",
    null);