This problem is utf-8 coding problem, if it is Utf-8+bom then there will be this problem, if it is pure utf-8 there is no such problem (of course, if you turn him completely ANSI, that is OK)
I encountered this problem when I read and write XML. Looked for a long time in the foreigner of an online saw the solution of the method. There are some methods that I have summed up myself.
public bool LoadXml (string xmlfile)
{
if (xmlDocument = = null)
{
throw new ArgumentNullException ("XmlDocument");
}
if (xmlfile = = NULL | | xmlfile.length = = 0)
{
throw new ArgumentNullException ("XMLFile");
}
Debug.Log (xmlfile);
TextReader tr = new StringReader (xmlfile);
XmlDocument.Load (TR);
System.IO.StringReader StringReader = new System.IO.StringReader (xmlfile);
StringReader.Read (); Skip BOM
System.Xml.XmlReader reader = System.Xml.XmlReader.Create (StringReader);
Xmldocument.loadxml (Stringreader.readtoend ());
return true;
}
This is the explanation of the BOM online a lot, I don't explain http://www.cnblogs.com/zhongru_tu/archive/2008/04/11/1147792.html
This is a self-written method of importing XML, the part of the comment is the method I started to use, the part that is not annotated I have modified. This way you can skip the BOM when you read the XML.
If you don't need to publish as a Web page, there's another way to do that, and that is to re-write the XML and completely change the way it's encoded without the BOM.
The code is as follows:
Encoding Utf8nobom = new UTF8Encoding (false);
String filestring = File.readalltext (Writeurl,utf8nobom);
File.writealltext (Writeurl,filestring,utf8nobom);
Note that you need to use several namespaces
Using System.Xml;
Using System.Text;
Using System;
Using System.IO;
Of course sometimes you will find unity although you have written a namespace but there are some classes you can not find, then you have to go to the web under the Special Dynamic Library (DLL) into the Plugins folder, of course, some read and write the local file of the class when published as a Web page when you are not able to use.
Finally, you use the above method will remember to change your XML file encoding Utf-8+bom This format, because we are reading the BOM format.
There are some other small ways you can use other editing software to change to Utf-8 without BOM, but sometimes it is possible to solve the problem, but when you are done, the above method may help you.
Unity3d xmlexception:text node cannot appear in the This state scheme