Unity3d xmlexception:text node cannot appear in the This state scheme

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.