Sax解析编码标签

3

I have xml Like:

<OuterTag>

    <InnerTag>

        <content:encoded><![CDATA[Huawei have entered the smartphone race by unveiling their own quad core devices and the Chinese...<br/>
        <br/>
        </div>]]>

        </content:encoded>

    </InnerTag>

</OuterTag>

我可以获取简单标签的所有值,但是我无法从<content:encoded>中获取。 我该如何解决?


你想解析 content:encoded 标签并从中获取数据吗? - Sumant
开始元素: if (localName.equals("content:encoded")) { contentOn = true; channelparse=false; }字符: if (contentOn==true && channelparse==false) {contentValue = new String(ch, start, length); contentOn = false; }结束元素: if (localName.equalsIgnoreCase("content:encoded")&& channelparse==false) {data.setcontent(contentValue); }获取: public ArrayList<String> gotcontent() { // TODO Auto-generated method stub return data.getcontent(); } - Nirupoma Saha Chaiti
2个回答

2

我最近也遇到了同样的问题,解决方法是在代码中使用encoded而不是content:encoded。

if (localName.equals("encoded")) // not content:encoded

0

请检查一下,它可能会解决你的问题

StringBuilder stringBuilder;

start element: 
       if (localName.equals("content:encoded")) 
       {
        contentOn = true; channelparse=false; 
        stringBuilder = new StringBuilder();
       }
       character: 
       if (contentOn==true && channelparse==false) 
       { 
         contentValue =""; 
         contentValue = new String(ch, start, length); 
         stringBuilder.append(contentValue);
         contentOn = false; 
       } 
      end element: 
      if (localName.equalsIgnoreCase("content:encoded")&& channelparse==false)
       { 
        data.setcontent(stringBuilder.toString()); 
       }
      get: public ArrayList<String> gotcontent() 
     { 
      return data.getcontent(); 
     } 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接