java - 检测文本内容是否有CDATA

标签 java xml cdata

我有两个用于获取应用程序描述的 API 和一个通用 UI。我需要在 Java 中检查描述是否带有 CDATA 标记。

例如,一个应用程序具有以下描述:

"<![CDATA[<p>What is Skype?<br />Skype is software that enables the world's     
conversations. Millions of individuals and businesses use Skype to make free video and voice    
calls, send instant messages and share files with other Skype users. Everyday, people also    
use Skype to make low-cost calls to landlines and mobiles.</p>]]>"

另一个应用有如下描述

Run with your fingers as fast as you can to try and get to the top of the leader board. This    
 game gets even better with friends, Once people see you playing they will want to have a go    
 and try to beat your fastest time. Tip: Take long strides on the screen to get maximum     
distance per step,     
<a href=https://abc.defgh.ij.kl/apps/wap/shopping/shopping/freshima-supermarket/freshima-supermarket/web/>WAP URL</a>

我如何区分这两种描述?在 Java 中有没有办法检测描述是否带有 CDATA

最佳答案

您如何解析 XML?

如果您使用的是 StAX,您可以获得在流中遇到的当前事件,它可能是 XMLStreamConstants.CHARACTERSXMLStreamConstants.CDATA.

如果您正在获取一个Node 对象(例如通过XPathAPI),该对象将为您提供一个getNodeType() 方法。 Node 也有 Node.TEXT_NODE 的常量和 Node.CDATA_SECTION_NODE

更多信息将有助于回答您的问题。

问候, 最大

关于java - 检测文本内容是否有CDATA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8999089/

相关文章:

xml - 关于 JAXP、XSLT 和 XML 保留字符

android - 错误 : resource array/com_google_android_gms_fonts_certs

java - 我对java中的返回方法感到困惑

java - 将 android 项目转换为库项目

java - Maven 模块 + 构建单个特定模块

xml - 强制清空 CDATA 元素

java - SOAPMessage 如何解析&lt;![CDATA[ ]]>?

java - 为什么优先级队列中的键应该是不可变的?

c# - 使用 REST XML Web 服务

xml - 开始使用 CDATA 是一个重大改变吗?