I have some code that receives some XML and there is the possibility that a CDATA tag element will be present. A flag is passed into the method that states whether the CDATA tag should be present, if the flag is false, then the CDATA tag should be removed if present, how would I do this without parsing the query.Value?
private static void CDataTagUtility(XmlDocument catalog, XElement newData, bool addCdataTag)
{
XElement query = newData.Element("Query").Element("CommandText");
if (addCdataTag)
{
XmlCDataSection encapsulatedQuery = catalog.CreateCDataSection(query.Value);
try
{
query.SetValue(encapsulatedQuery.OuterXml);
}
catch (ArgumentException exc) { /*Thrown due to CDATA tag already present - ignore*/ }
}
else //check for cdata tag - remove if present
{
//How do I remove the CDATA encapsulation tag???
}
}