Search code examples
xmlcdata

Can you have multiple tags with xml tag having CDATA section?


I have an xml file that looks like this :

 <bookstore>  

 <book category="COOKING">  
   <title lang="en">Everyday Italian</title>  
   <author>Giada De Laurentiis</author>  
   <year>2005</year>  
   <price>30.00</price>  
   <![CDATA[<<port>url=  https://localhost:8080<port>]]>
 </book>

I see that when this is processed, the entire tag is considered as CDATA. Can you use other tags inside a tag having CDATA? I did not find any online samples that did this.


Solution

  • First, you seem to be unclear what a "tag" is. Given this:

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

    there are two tags: a start tag <a> and an end tag </a>. The CDATA section is not "in" a tag, it is between two tags.

    So when you say 'the entire tag is considered as CDATA' I think you mean 'the entire content between the tags is considered as CDATA'; and yes, that is correct. And when you say 'Can you use other tags inside a tag having CDATA?' I think you mean 'can you have tags inside a CDATA section?', and the answer is no: the only point of using a CDATA section is to prevent any angle brackets inside the section being recognized as markup.