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.
<
Less than ( < )
>
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 (<
) for your less-than sign? I believe that will get you around the issue.
You could use the XML entity <
. This Wikipedia page has a good list of XML entities.
精彩评论