使用 SAX 进行 XML 解析:如何在 xml-tags 中将 html 作为文本处理 [英] XML parsing with SAX: how to handle html as text within xml-tags

查看:42
本文介绍了使用 SAX 进行 XML 解析:如何在 xml-tags 中将 html 作为文本处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到来自外部服务器的 xml 响应.

I get an xml response from an external server.

通过一些教程,我让 SAX-Parser 工作起来.

Using some tutorials I got SAX-Parser working.

还有一个小问题.

在响应中有例如包含这样的 html 的描述标签:

Within the response there is e.g. description tag containing html like this:

<description><p><strong>Title</strong></p>Description</description> 

解析我的对象的描述字段后只包含<".

After parsing description field of my object contains only "<".

是否可以告诉我的解析器将 html 处理为纯文本?

Is it possible to tell my parser to handle html as plain text?

或者也许还有其他可能来解决这个问题.

Or maybe there are other possibilities to solve this problem.

谢谢.

推荐答案

因为你没有包含你的代码,我不得不想象你写了什么.SAX 处理程序实现中的一个常见错误是不处理元素文本可能在多个 characters() 方法调用中返回的事实.您需要将它们聚合在一起,直到获得 endElement() 事件.

since you don't include your code, i have to imagine what you wrote. a common bug in SAX handler implementations is not handling the fact that the element text may be returned in multiple characters() method calls. you need to aggregate them all together until you get the endElement() event.

这篇关于使用 SAX 进行 XML 解析:如何在 xml-tags 中将 html 作为文本处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆