2013-10-06 142 views
1

我有xml解析以下内容。Android:解析标签包含android内容中的html内容

   <body> 
        <body.content> 
        <p>This is testing content.</p> 
        <p>This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.This is testing content.</p>  
        </body.content> 
       </body> 

我有这个XML的解析器方法。

bodyTag.getChild(body_content).setEndTextElementListener(new EndTextElementListener() { 

      @Override 
      public void end(String body) { 
       System.out.println(body); 

      } 
     }); 

我的问题是当我解析这个XML我得到了下面的异常。

10-06 15:39:21.976:E/AndroidRuntime(1110): 了java.lang.RuntimeException:android.sax.BadXmlException:致线86:命名为文本元素内 遇到混合内容' body.content”。

问题是sax解析器无法解析html <p>标记。 我想知道有什么方法可以通过sax解析器来解析html content

感谢

回答

0

你可以使用Jsoup库:http://jsoup.org/ 它`很容易与HTML/XML标签治疗..

+0

jsoup用于解析html标记。是吗?我的要求是解析xml标签中包含的html上下文。 – user1156041

0

你可以试试这个。

<content><![CDATA[Your stuff here with all the <em>HTML</em> tags you can think of.]]></content> 

我想this link帮助你为它很容易理解。

+0

我请求服务器获取xml文件。我没有机会像这样添加CDATA。 – user1156041