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

私は smth が 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 に答える