0

我有这个 RSS 提要要解析,其中包含几个标签。我能够检索除描述标签节点之外的所有值(子元素)。请在 RSS 源下方找到

<fflag>0</fflag>
<tflag>0</tflag>
<ens1:org>C Opera Production</ens1:org>
−
<description>
<p>Opera to be announced</p>

<p>$15 adults/$12 seniors/$10 for college students<span style="white-space: pre;"> </span></p>
</description>

我为此使用的代码是

    StringBuffer descriptionAccumulator = new StringBuffer();

else if (property.getNodeName().equals("description")){
                    try{
                        String desc = (property.getFirstChild().getNodeValue());
                        if(property.getNodeName().equals("p")){
                            descriptionAccumulator.append(property.getFirstChild().getNodeValue());
                        }
                    }
                    catch(Exception e){
                        Log.i(tag, "No desc");
                    }
else if (property.getNodeName().equals("ens1:org")){
                try{

                        event.setOrganization(property.getFirstChild().getNodeValue());
                        Log.i(tag,"org"+(property.getFirstChild().getNodeValue()));
                    }
                    catch(Exception e){

                    }
else if (property.getNodeName().equals("area")||property.getNodeName().equals("fflag") || property.getNodeName().equals("tflag") || property.getNodeName().equals("guid")){
                    try{
                        //event.setOrganization(property.getFirstChild().getNodeValue());
                        Log.i(tag,"org"+(property.getFirstChild().getNodeValue()));
                    }
                    catch(Exception e){

                    }
else if(property.getNodeName().equals("p") || property.getNodeName().equals("em") || property.getNodeName().equals("br") || property.getNodeName().startsWith("em") || property.getNodeName().startsWith("span") || property.getNodeName().startsWith("a") || property.getNodeName().startsWith("div")  || property.getNodeName().equals("div")  || property.getNodeName().startsWith("p")){
                    descriptionAccumulator.append(property.getFirstChild().getNodeValue());
                    descriptionAccumulator.append(".");
                    System.out.println("description added:"+descriptionAccumulator);
                    Log.i("Description",descriptionAccumulator+property.getFirstChild().getNodeValue());


                }

我尝试捕获<description>标签的值,但效果很好,所以我尝试使用所有常用的 html 格式化标签,但仍然没有出路。使用任何其他解析器不是一种选择。有人可以帮我解决这个问题。谢谢

4

2 回答 2

1

我相信 rss xml 有问题。例如检查StackOverflow rss feed返回了什么 xml 。特别注意<summary type="html">节点内容的外观 - 它内部没有子 xml 节点,只有纯 xml 转义文本。因此,如果在您的情况下可以接受 - 将精力花在正确的 rss xml 生成上,而不是解决后果。

于 2011-01-10T19:26:23.337 回答
0

您将其解析为 xml,因此描述标签没有字符串值,它有多个子项。您可以尝试获取描述节点并漂亮地打印它的子节点。有关打印到 XML 的信息,请参阅LSSerializer

于 2011-01-10T18:47:33.667 回答