locked
Enable to load XML string RRS feed

  • Question

  • User1192570106 posted

    Hi All,

    Below is my code. I want to load this XML but throwing error.

    An unhandled exception of type 'System.Xml.XmlException' occurred in System.Xml.dll

    Additional information: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 1, position 93.

    String p = "<Question IsPassage='1' QuestionTypeID='1' QuestionSubTypeID='1' PassageText='&lt;![CDATA[ <p>A</p>]]&gt;' QuestionText='&lt;![CDATA[ <p>B</p>]]&gt;' ><Answers><Answer OptionOrder='1' Optiontext='A' iscorrect='true' /><Answer OptionOrder='2' Optiontext='B' iscorrect='false' /></Answers></Question>";
    XmlDocument docXML = new XmlDocument();
    docXML.LoadXml(p);

    Need help on this to modify XML string in proper format so that it can Load.

    Thanks in advance..

    Friday, September 16, 2016 2:01 PM

Answers

  • User283571144 posted

    Hi Pratap09,

    Need help on this to modify XML string in proper format so that it can Load.

    As far as I know, xml file cannot use '<' and '>' characters except for the tags.

    Normally, we need to use &lt; and &gt; entities to represent < and > in any values within the XML file.

    More details, you could refer to follow codes:

           String p = "<Question IsPassage='1' QuestionTypeID='1' QuestionSubTypeID='1' PassageText='&lt;![CDATA[ &lt;p&gt;A&lt;/p&gt;]]&gt;' ><Answers><Answer OptionOrder='1' Optiontext='A' iscorrect='true' /><Answer OptionOrder='2' Optiontext='B' iscorrect='false' /></Answers></Question>";
                XmlDocument docXML = new XmlDocument();
                docXML.LoadXml(p);

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 19, 2016 5:32 AM