Hi!,
I’m trying to load a XML file and so far I got it, but I get the infamous “text node can’t appear in this state”. Something to do with the BOM encoding.
Anyways, I tried this:
//--------------------------------------------------------------------------
import System.Xml;
import System.IO;
//--------------------------------------------------------------------------
function GetTextWithoutBOM(textAsset : TextAsset)
{
var memoryStream : MemoryStream = new MemoryStream(textAsset.bytes);
var streamReader : StreamReader = new StreamReader(memoryStream, true);
var result : String = streamReader.ReadToEnd();
streamReader.Close();
memoryStream.Close();
return result;
}
//--------------------------------------------------------------------------
function loadLevel(archXML : String){
var xmlDoc : XmlDocument = new XmlDocument();
var ta : TextAsset = Resources.Load(“/Assets/Materials/XML/Levels/10/test.xml”);
Debug.Log(ta); // — Returns NULL always
var noBom: String = GetTextWithoutBOM(ta);
xmlDoc.LoadXml(noBom);
...
//--------------------------------------------------------------------------
But now I geting an “Object reference not set to an instance of an object” error, and I realize with the “Debug.Log” line that “Resources.Load” never load the file (it’s null always).
But, I know that the path to the file is Ok, because, when I use just this:
xmlDoc.LoadXml(“test.xml”);
- or -
xmlDoc.LoadXml(“/Assets/Materials/XML/Levels/10/test.xml”);
It works fine but I get the “Text node canot appear in this state” error in the first character.
What I’m doing wrong??
I’m stuck.
Thanks