- Home /
Upgrading to 4.0 breaks my XML reader
Perhaps there's another workaround or explanation for this, but I didn't see anything in the update that should be impacting this.
The error that fires when the project is upgraded to 4.0 is:
XmlException: Text node cannot appear in this state. Line 1, position 1. This fires at "xmlStory.LoadXml(stringReader.ReadToEnd());"
the relevant code posted below. Note the BOM stripper worked fine before, but after the upgrade it sends the error whether I use an XML file with a BOM or not (tried both).
 // Gets ALL the scenes.
     void GetScenes ()
     {
         //initialize
         scenes = new Dictionary<string,Scene>();
         
         //TODO: doublecheck this isnt cvausing mass slowdown
         //BOM STRIPPER
         XmlDocument xmlStory = new XmlDocument();
         System.IO.StringReader stringReader = new System.IO.StringReader(xmlScriptRef.text);
         stringReader.Read(); // skip BOM
         xmlStory.LoadXml(stringReader.ReadToEnd());
                 
         //XmlDocument xmlStory = new XmlDocument();//new xmlDoc
         //xmlStory.LoadXml(xmlScriptRef.text);//load file
         
         XmlNodeList sceneList = xmlStory.GetElementsByTagName("scene"); //array of scenes
         
         foreach (XmlNode sceneInfo in sceneList)//foreach scene in list
         {
             Scene newScene = new Scene(sceneInfo); //builds scene out of xmlnode data
             scenes.Add(newScene.title, newScene); // add whole obj dictionary in the scenes[].
         
             if (currentScene == null) //if there isnt a currentscene yet
             {
                 ChangeScene(newScene.title);//change to first scene
                 //currentScene=newScene;//put in the first scene you get
             }
         }
     }
I second that. Unity4 apparently treats X$$anonymous$$L files differently. I could get around using XmlSerializer, but it's obviously not ideal.
NOTE: For those interested, here's where I got the bom stripper in the first place: http://answers.unity3d.com/questions/10904/xmlexception-text-node-canot-appear-in-this-state.html
I ended up switching to TSV anyway, so I'm not sure if this problem was ever resolved.
Your answer
 
 
             Follow this Question
Related Questions
A node in a childnode? 1 Answer
JSON vs XML for Unity C# 1 Answer
C# Saving Values to XML 1 Answer
Parse xml with unknown fields 1 Answer
Best practice to store and load a specific set of objects? 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                