Thursday, July 30, 2009

Read CDATA value from XML.

We can create cData node like this.
xmlDocumentInstance.CreateCDataSection(tbVisInfo.Text))


We can to read the value of cData node by using the following function

private string GetValueFromCData(string cDataValue)
{
XmlDataDocument xmlDoc = null;
XmlElement root = null;
string value = string.Empty;

try
{
xmlDoc = new XmlDataDocument();
xmlDoc.LoadXml("" + cDataValue + "");
root = xmlDoc.DocumentElement;
value = root.FirstChild.InnerText;


}
catch (Exception GetValueFromCDataException)
{
throw GetValueFromCDataException;
}
finally
{ }

return value;

}

1 comment:

  1. Hi Kavita I am new to web development I just want to extract tag and its value within it. I store my xml string in sql database. So help me what to do?

    ReplyDelete