Hello, I’m trying to iterate through an XML file. I have nested iterations that are returning more data (all of it, actually) than I intend.
The xml is here:
http://www.oldno19.com/upload/timeline.xml
Here is my code:
function loadXML() {
var www = new WWW ("http://www.oldno19.com/upload/timeline.xml");
yield www;
var xml = new XmlDocument();
xml.LoadXml(www.text);
var i : int = 1;
for (var node in xml.SelectNodes ("/how_we_got_here_stories/year/title")) {
var thisCube = Instantiate(cube, Vector3 (i*1.25, 1, 0), Quaternion.identity) as Transform;
yearTxt = thisCube.Find("YearText").GetComponent(TextMesh);
titleTxt = thisCube.Find("TitleText").GetComponent(TextMesh);
yearTxt.text = node.InnerText;
thisCube.transform.parent = this.transform;
i++;
for (var node2 in node.SelectNodes ("/how_we_got_here_stories/year/how_we_got_here_story/title")) {
var thisCube2 = Instantiate(cube, Vector3 (i*1.25, 1, 0), Quaternion.identity) as Transform;
yearTxt = thisCube2.Find("YearText").GetComponent(TextMesh);
titleTxt = thisCube2.Find("TitleText").GetComponent(TextMesh);
yearTxt.text = "";
titleTxt.text = WrapTxt(node2.InnerText,charLimit);
thisCube2.transform.parent = this.transform;
i++;
}
}
}
In the 2nd for-loop, I want it to iterate through the first <“year”>'s children and return the <“how_we_got_here_story”> items that appear under the first year… then do the same for the next <“year”>… but for each year, i end up with EVERY <how_we_got_here_story> item.
I have been searching the msdn pages for xmldocument methods, but I’m uncertain how to use them since they don’t give javascript examples.
Guess I should learn C# soon.
Thanks in advance!