Add html tags in XML

By bryan tugade

What if we use xml as our database? And sometimes we also want to save the data as html or the whole html source code. We can do this by using character data or simply CDATA. The format for this is "<![CDATA[ ]]>" . Here's a simple snippets on how to add it in xml.

<?xml version="1.0" encoding="utf-8" ?>
<products>
    <product>
       <imageurl>http://static.eggheadcafe.com/images/EggHeadCafeLogoTransparent.png</imageurl>
        <modelName>This is logo</modelName>
        <type>snippets</type>
       <description> <![CDATA[  <p>        Logo : the logo</p>    <p>        category : Information Technology</p>    <table class="style1">        <tr>            <td class="style2">                This is a table</td>             <td>                 </td>         </tr>    </table>
]]></description>
    </product>
</products>

The html tags should be put inside the  cdata like this one "<![CDATA[ <p> insert your html tags here...  </ p >]]> "

this is the output :


Related FAQs

This is to show you on how to retrieve content data in the childnodes of xml and show it in web page using response.write.
Add html tags in XML  (1551 Views)