1

I am trying to parse an XML with CDATA elements...my below code blows up if content in CDATA is xml encoded...is there any way i can decode all the xml before i parse..

---Code to parse

if (formText.FirstNode.NodeType == XmlNodeType.CDATA) { return formText.Value; }
else { throw new applicatinException("ERROR")}

this code works if formText has

  "<Text><![CDATA[Sample Text<b>BoldText </b>]]></m:FormText>"

but blows up if formText has (encoded values)

  "<Text>&lt;[CDATA[Sample Text &lt;b&gt;BoldText&lt;/b&gt; ]]&gt;</m:FormText>"
srjt
  • 316
  • 2
  • 10

1 Answers1

1
"<Text>&lt;[CDATA[Sample Text &lt;b&gt;BoldText&lt;/b&gt; ]]&gt;</m:FormText>"

This is not a CDATA segment, it is a text segment. You will have to handle it as basic text and handle extracting the CDATA information yourself. By encoding the CDATA information, you have made it no longer match that format.

Guvante
  • 18,775
  • 1
  • 33
  • 64