I’m having a bit of trouble when trying to use xml files for loading ( and eventually saving aswell ) Haven’t worked with .xml files earlier so I’m kinda clueless.
Anyways, I’m using the Lightweight xml parser created by Fraser McCormick, but I found a version of it through google that was converted into C# since that’s the language I’m using.
What I’m doing atm is a mission-system kind of thing, I start with a Level class ( that derieves from Monobehaviour, the other classes does not! ) in which I specify which xml to read and the amount of missions of the level, for each mission I create a new Mission class at runtime, the Mission class is set up to read how many objectives the mission contain and create a new Objective class for each of them.
My problem is when I’m trying to grab data from the xml. I get the error
FormatException: Input string was not in the correct format
System.Int32.Parse (System.String s)
XMLNode.GetObject (System.String path) (at Assets/xml/XMLNode.cs:32)
XMLNode.GetValue (System.String path) (at Assets/xml/XMLNode.cs:17)
Mission.SetupMission () (at Assets/Code/Quest/Mission.cs:55)
LevelMiLogic.SetupMissionLogic () (at Assets/Code/Quest/LevelMiLogic.cs:27)
LevelMiLogic.Start () (at Assets/Code/Quest/LevelMiLogic.cs:17)
I press the error in the console and the XMLNode class from Lightweight pops open, highlighting this : currentNode = (XMLNode)currentNodeList[int.Parse(bits*)];* *from the GetObject method : private object GetObject(string path)*
-
{*
-
string[] bits = path.Split('>');* -
XMLNode currentNode = this;* -
XMLNodeList currentNodeList = null;* -
bool listMode = false;* -
object ob;* -
for (int i = 0; i < bits.Length; i++)* -
{* -
if (listMode)*
{
currentNode = (XMLNode)currentNodeList[int.Parse(bits*)];*
ob = currentNode;
* listMode = false;*
* }*
* else*
* {*
_ ob = currentNode[bits*];*_
* if (ob is ArrayList)*
* {*
* currentNodeList = (XMLNodeList)(ob as ArrayList);*
* listMode = true;*
* }*
* else*
* {*
* // reached a leaf node/attribute*
* if (i != (bits.Length - 1))*
* {*
* // unexpected leaf node*
* string actualPath = “”;*
* for (int j = 0; j <= i; j++)*
* {*
* actualPath = actualPath + “>” + bits[j];*
* }*
* //Debug.Log("xml path search truncated. Wanted: " + path + " got: " + actualPath);*
* }*
* return ob;*
* }*
* }*
* }*
* if (listMode)*
* return currentNodeList;*
* else*
* return currentNode;*
* }*_</em> <em>_*However... considering the fact that it's the first time I'm playing around with the xml thingies I believe it's more likely something with my code that's wrong so here's the method in my Mission class that's somehow probably causing the problem:P (Posted the stuff above just in case neways) : private void SetupMission() {*
* //We want to read an xml file and load all necessary data from it*
* //if no xml file matching the requested name (playername.ToString() + Levelname.ToString() + .xml)*
* //we create a new one from the default*
* XMLParser parser = new XMLParser();*
* _myLogic.xmlNode = parser.Parse( _myLogic.xmlFile.text );*
* //miName = myLogic.xmlNode.GetValue( “Missions>Mission>Mi” + miIndex + “>MiName” );
//Debug.Log( miName );
Debug.Log( myLogic.xmlNode.GetValue( “Missions>Mission>Mi0>MiName” ));*
* }*_</em> <em>_*oh! and the .xml file is like this ( only the beginning of it since that's the only part I'm using atm ) *
* *
*
“MissionOne”`
:)I’ld really appreciate some help with this, and if someone knows of a good site where I can read a little further on how to use .xml with c# I’ld appreciate if that person could share it aswell. Have looked through MSDN quickly but I didn’t get very much clarity from it.*_