开发者

How do I format a '<' char in C# code in an xml document?

I have an XML file that has data in it, but one of the things in it is a section of C# code that is intended for a script for a program.

The problem is I have this code in there for a data table,

for (i开发者_Python百科nt i = 0; i < dt.Rows.Count; ++i)

The XML deserialization is getting caught up on the '<' char, for obvious reasons. I already tried escaping it with '\', but that did not work.

Is there a way to have this code in the XML document and have it parse/deserialize correctly? I can change the code to:

dt.Rows.Count > i

...and it works, but I want to see if there is a way for the other code to work as well.


&lt; Less than ( < )

&gt; Greater than ( > )

Or you can look into CDATA


When I pass code or the like in Xml I use a CData tag

 <CodeData>
  <![CDATA[
    <DontParseAsXml>
        Data
    </DontParseAsXml>
   ]]>
 </CodeData>


I'm not sure whether or not this will work in your case, but have you tried using an entity (&lt;) for your less-than sign? I believe that will get you around the issue.


You could use the XML entity &lt;. This Wikipedia page has a good list of XML entities.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜