Xml加载出错

在加载xml文件的时候xmlDoc.LoadXML()可能会出现这样的错误

XmlException: Text node cannot appear in this state. Line 1, position 1. 

Mono.Xml2.XmlTextReader.ReadText (Boolean notWhitespace) 

Mono.Xml2.XmlTextReader.ReadContent () Mono.Xml2.XmlTextReader.Read () 

出现这个错误的原因是因为Unity3D加载XML文件的时候,XML文件必须保存为UTF-8编码的格式,同时还必须去掉开头的两个字节(BOM)用来标识UTF-8用的。这时你可以选择一些编辑工具另存为UTF-8,(有些工具默认的会为UTF-8编码添加一个BOM标识),比如你可以使用eclipse导出xml,这样就不含有BOM标识。还有其他一些解决办法:给个链接吧:http://answers.unity3d.com/questions/10904/xmlexception-text-node-canot-appear-in-this-state.html

猜你喜欢

转载自blog.csdn.net/qq_32260719/article/details/79926824
今日推荐