I have an xml file with a node that contains some c# code.
<Script Name="WrapText">
var sb = new System.Text.StringBuilder();
int lastSpaceIndex = 0;
for(int i = 0; i < paragraph.length; i++)
{
var curChar = paragraph[i];
sb.Append(curChar);
if (System.Char.IsWhiteSpace(curChar))
{
lastSpaceIndex = i;
}
if (i % splitlength == 0)
{
if (lastSpaceIndex != 0)
{
sb[lastSpaceIndex] = '\n';
}
}
}
return sb.ToString();
</Script>
when i try to load this using an XmlDocument and XmlReader classes in C# like this:
XmlReader xReader = XmlReader.Create(new MemoryStream(ASCIIEncoding.UTF8.GetBytes(imml)), _ReaderSettings);
XmlDocument xDoc = new XmlDocument();
xDoc.Load(xReader);
I get this error:
Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 25, position 21.
If I remove the for loop line, it loads the file without any problems.
Why is this happening?