views:

503

answers:

2

I use ASP.net VB.net to write a XML file.

In one of the element which is called "Description" i have to add a "<![CData[Class : <b>Class Name</b><br>Price: 100,000.00]]>".

Using,

strDes = "<![CDATA[Class : <b>" + myReader.GetSqlValue(4).ToString + 
    "</b><br>Price: " + myReader.GetSqlValue(7).ToString + "]]>"
XMLwrite.WriteElementString("description", strDes.ToString)

But when i generate the XML file, it gives

<description>&lt;![CDATA[Class : &lt;b&gt;Residential - Site Built&lt;/b&gt;&lt;br&gt;Price: 100,000.00]]&gt;</description>
A: 

If you are writing a CDATA section, you can use WriteCData method instead.

shahkalpesh
+1  A: 

You should always use the XML APIs to create XML. The CDATA you were generating should have been generated by the XmLWriter API. Try this:

strDes = "Class : <b>" + myReader.GetSqlValue(4).ToString + _
    "</b><br>Price: " + myReader.GetSqlValue(7).ToString
XMLwrite.WriteStartElement("description")
XMLwrite.WriteCData(strDes);
XMLwrite.WriteEndElement();
John Saunders
I did this already. Had a hunch. However thank you very much.
Kush