Pages

Showing posts with label html tags in xslt. Show all posts
Showing posts with label html tags in xslt. Show all posts

Sunday, September 8, 2013

How to write HTML tags in XML using CDATA (disable-output-escaping)-C#

              
C# code to write XML:

                   XmlWriter writer = XmlWriter.Create(MapPath("xmls1.xml"))
                   writer.WriteStartDocument();
                    writer.WriteStartElement("root");
                    writer.WriteStartElement("Items");        // Create subroot
                    for (int col = 0; col < 5; col++)
                    {

                        writer.WriteStartElement("Title");
                        writer.WriteCData("<b>HI</b>This is title");
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();                // End subroot

                    writer.WriteEndElement();                  
                    writer.WriteEndDocument();



Output :

<?xml version="1.0" encoding="utf-8"?>
<root>

<items>
    <
Title><![CDATA[<b>HI</b>This is title]]></Title>
  </items>

.......
</root>




NOTE :

When Transform the XML using XSLT , Set disable-output-escaping="yes", to get the output same as in node i.e with html tags.

<xslt:foreach select="root/items">
 <h1>
          <xsl:value-of select="title" disable-output-escaping="yes"/>
 </h1> 

</xsl:foreach>