我有两个用于获取应用程序描述的 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.CHARACTERS
或 XMLStreamConstants.CDATA
.
如果您正在获取一个Node
对象(例如通过XPathAPI),该对象将为您提供一个getNodeType()
方法。 Node
也有 Node.TEXT_NODE
的常量和
Node.CDATA_SECTION_NODE
。
更多信息将有助于回答您的问题。
问候, 最大
关于java - 检测文本内容是否有CDATA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8999089/