检测文本内容是否有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
?
I have two api for getting a description of apps and one common UI. I need to check whether the description come with CDATA
tag or not in Java.
For example, one app has the following description :
"<![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>]]>"
And another app has the following description
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>
How can I differentiate there two description? Is there a way to detect whether the description comes with CDATA
or not in Java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您如何解析 XML?
如果您使用的是 StAX,您可以获取在流中遇到的当前事件,该事件可能是
XMLStreamConstants.CHARACTERS
或XMLStreamConstants.CDATA
。如果您正在获取一个
Node
对象(例如通过 XPathAPI),该对象将为您提供一个getNodeType()
方法。Node
还具有Node.TEXT_NODE
的常量和Node.CDATA_SECTION_NODE
。更多信息将有助于回答您的问题。
问候,
最大限度
How are you parsing your XML?
If you are using StAX, you can get the current event that you encounter in your stream, which might be
XMLStreamConstants.CHARACTERS
orXMLStreamConstants.CDATA
.If you are getting a
Node
Object (like for instance via XPathAPI), the Object will offer you agetNodeType()
Method. AlsoNode
has Constants forNode.TEXT_NODE
andNode.CDATA_SECTION_NODE
.More Information would be helpful answering your question.
Regards,
Max
您不应该以不同的方式对待以下两个示例,因为就 XML 而言,它们只是转义相同内容的不同方式:
因此,也许您的测试只是“文本内容是否包含
<字符?”。
You should not be treating the following two examples differently, because as far as XML is concerned, they are just different ways of escaping the same content:
So perhaps your test is simply "does the text content contain a
<
character?".