Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect whether the text content has CDATA

Tags:

java

xml

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?


1 Answers

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

like image 55
Max Avatar answered Mar 03 '26 08:03

Max



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!