检测文本内容是否有CDATA

发布于 2024-12-28 17:35:25 字数 1036 浏览 0 评论 0原文

我有两个用于获取应用程序描述的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

芸娘子的小脾气 2025-01-04 17:35:25

您如何解析 XML?

如果您使用的是 StAX,您可以获取在流中遇到的当前事件,该事件可能是 XMLStreamConstants.CHARACTERSXMLStreamConstants.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 or XMLStreamConstants.CDATA.

If you are getting a Node Object (like for instance via XPathAPI), the Object will offer you a getNodeType() Method. Also Node has Constants for Node.TEXT_NODE and
Node.CDATA_SECTION_NODE.

More Information would be helpful answering your question.

Regards,
Max

傾旎 2025-01-04 17:35:25

您不应该以不同的方式对待以下两个示例,因为就 XML 而言,它们只是转义相同内容的不同方式:

<a><![CDATA[<xyz/>]]></a>

<a><xyz/></a>

因此,也许您的测试只是“文本内容是否包含 <字符?”。

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:

<a><![CDATA[<xyz/>]]></a>

<a><xyz/></a>

So perhaps your test is simply "does the text content contain a < character?".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文