我有两个用于获取应用程序描述的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?
发布于 2012-01-25 17:56:04
您如何解析您的XML?
如果您使用的是StAX,则可以获取在流中遇到的当前事件,该事件可能是XMLStreamConstants.CHARACTERS或XMLStreamConstants.CDATA。
如果您正在获取一个Node对象(例如,通过XPathAPI),该对象将为您提供一个getNodeType()方法。此外,Node具有用于Node.TEXT_NODE和Node.CDATA_SECTION_NODE的常量。
更多信息将有助于回答您的问题。
向您致敬,Max
发布于 2012-01-25 19:00:46
您不应该区别对待以下两个示例,因为就XML而言,它们只是转义相同内容的不同方式:
<a><![CDATA[<xyz/>]]></a>
<a><xyz/></a>因此,您的测试可能只是“文本内容是否包含<字符?”。
https://stackoverflow.com/questions/8999089
复制相似问题