Is it possible to identify if the node is of Text or CDATA type?

Viewed 16

My XML looks like this

    <?xml version = "1.0"?>
    <class>
       <student rollno = "393">
          <firstname>tom</firstname>
          <lastname>hardy</lastname>
          <nickname>bane</nickname>
          <marks>85</marks>   
          <url><![CDATA[<a href="https://mywebsite.com/profile/_hp9vxLqVEemS8tVvw_nqJA">https://mywebsite.com/profile/_hp9vxLqVEemS8tVvw_nqJA</a>]]></url>
       </student>
       
       <student rollno = "493">
          <firstname>tom</firstname>
          <lastname>cruise</lastname>
          <nickname>maveric</nickname>
          <marks>95</marks>
          <url>https://mywebsite.com/profile/_hp9vxLqVEemS8tVvw_nqJA</url>
       </student>

   
   <student rollno = "593">
      <firstname>clark</firstname>
      <lastname>kent</lastname>
      <nickname>supes</nickname>
      <marks>90</marks>
      <url><![CDATA[<a href="https://mywebsite.com/profile/_hp9vxLqVEemS8tVvw_nqJA">https://mywebsite.com/profile/_hp9vxLqVEemS8tVvw_nqJA</a>]]></url>
   </student>
</class>

I am using DOM to parse the nodes in Java.

For all the nodes, in a loop, i use .getTextContent() to get the content. This works but for the Cdata content, I get the complete content including a href.

I only need the url. Are there any way to identify if the type is CDATA or text? I was thinking if CDATA, then extract the content and get only the url.

thank you.

0 Answers
Related