- Home /
Loading xml without loops
Problem : I can load the values from my xml however the values are being loaded repeatedly for 4 times -- in this case i'm getting the person's position. however i do not see any loops in my method that could cause this. I would like to stop it at the first time when all players positions have been loaded. Any help will be much appreciated. Thanks!
My xml and code are as follows :
<?xml version="1.0" encoding="utf-8"?>
<character>
<persons>
< person id="0" name="James">
<position x="0.1289005" y="0.8196044" z="0.03671255" />
</person>
<person id="1" name="Dean">
<position x="0.07401515" y="0.8196141" z="-0.001237739" />
</person>
</persons>
</character>
and a load xml method :
void LoadXML() {
{ path = Application.dataPath + name + ".xml";
XmlDocument xmlDoc = new XmlDocument ();
if (File.Exists (path)) {
xmlDoc.Load (path);
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("position");
for(int i=0; i<nodeList.Count; i++){
string x = nodeList[i].Attributes["x"].Value;
string y = nodeList[i].Attributes["y"].Value;
string z = nodeList[i].Attributes["z"].Value;
Debug.Log(x+" "+y+" "+ z);
}Debug.Log("stop");
}
}
The output looks something like this
x , y , z (positions for person 1)
x, y , z (positions for person 2)
stop
x , y , z (positions for person 1)
x, y , z (positions for person 2)
stop
x , y , z (positions for person 1)
x, y , z (positions for person 2)
stop
x , y , z (positions for person 1)
x, y , z (positions for person 2)
stop
Note * Im not using serializer here
Simply to ensure that the context is clear, where are you calling LoadX$$anonymous$$L() from and do you have only one object in your scene running this script?
It's certainly a rudimentary line of questioning, but what you've provided offers no obvious hints as to what the problem might be (which is good for the code, but bad for what you're currently experiencing).
$$anonymous$$y loadxml() script is from a script that loads and saves a user's position base on the getkeydown function. And yes, I have attached this game to only one object.
Base on my gut feeling (on why there is a repetition of 4) I'm actually thinking if its affected by the character, persons , person nodes which lead the the repetition in output. If so then how should i edit my loadxml method to get the results i want?
If this still hasn't been resolved yet in any way, I'm curious about something else now.
You say that when you tried "Get$$anonymous$$eyDown()" it looped twice...
Are you running "Get$$anonymous$$eyDown()" (or similar) from OnGUI() or from Update()? OnGUI() would cause it to run twice, for example.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Best way to save to playerprefs scriptableObjects 0 Answers
How do I use this XML reader? 1 Answer
XML Load unauthorized access 2 Answers
Serilaization queries 0 Answers