0
`使用UnityEngine;使用System.Collections的 ; using System.Collections.Generic; using System.Text;使用System.Xml的 ;使用System.IO的 ;在Unity内部加载XML
public class xmlhandler{
public XmlNodeList GetData(string xmlfilepath,string tag)
{
XmlDocument xmlDoc = new XmlDocument(); // xmlDoc is the new xml document.
TextAsset textAsset = (TextAsset)Resources.Load(xmlfilepath, typeof(TextAsset));
xmlDoc.Load(textAsset.text); // load the file.
XmlNodeList data = xmlDoc.GetElementsByTagName(tag); // array of the level nodes.
return data;
}
}
`
我似乎无法能够获得XML正确加载。这是正确的路径,当被调用时,我检查了一切。我不确定要提供什么其他信息。我假设我只是没有使用正确的功能或东西。对于不知道发生了什么,感到抱歉。
我得到的错误是
ArgumentException: Illegal characters in path.
System.IO.Path.IsPathRooted (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Path.cs:508)
System.IO.Path.InsecureGetFullPath (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Path.cs:357)
System.IO.Path.GetFullPath (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Path.cs:289)
System.Xml.XmlResolver.ResolveUri (System.Uri baseUri, System.String relativeUri)
System.Xml.XmlUrlResolver.ResolveUri (System.Uri baseUri, System.String relativeUri)
Mono.Xml2.XmlTextReader.GetStreamFromUrl (System.String url, System.String& absoluteUriString)
Mono.Xml2.XmlTextReader..ctor (System.String url, System.Xml.XmlNameTable nt)
System.Xml.XmlTextReader..ctor (System.String url, System.Xml.XmlNameTable nt)
System.Xml.XmlDocument.Load (System.String filename)
xmlhandler.GetData (System.String xmlfilepath, System.String tag) (at Assets/Resources/scripts/xmlhandler.cs:13)
structure_mercenarypost.Start() (at Assets/Resources/scripts/structures/structure_mercenarypost.cs:24)
什么是你给的Xmlfilepath。因为你的错误是说,它包含非法字符。 –
info = xml.GetData(“scripts/structures/structuresxml”,“structure”); –
如果'info'是你通过的路径。然后我可以理解它是失败的。你需要文件路径。 –