Game Development Reference
In-Depth Information
an xml file
//Using Last Child to Skip the <?xml
version="1.0" encoding="UTF-8"?>
//If we load from the xml file we will use the
FirstChild instead
_root = _doc.LastChild;
if (_root.HasChildNodes ) {
_userLength = _root.ChildNodes.Count;
_users = new UserData[_userLength];
for (var i : int = 0; i < _userLength; i++) {
if
(_root.ChildNodes[i].InnerText.Contains("No entries
yet.") == false) {
var nameAtt : XmlAttribute =
_root.ChildNodes[i].Attributes["name"];
var scoreAtt : XmlAttribute =
_root.ChildNodes[i].Attributes["score"];
var user : UserData = new UserData();
user.name = nameAtt.Value;
user.score = parseInt(scoreAtt.Value);
_users[i] = user;
} else {
break;
}
}
}
}
}
// C# user:
public static class XMLParser {
public static int usersLength {
get { return _usersLength; }
}
public static void Parse( string xml) {
_doc = new XmlDocument();
_doc.LoadXml(xml); // Loading from String
Search WWH ::




Custom Search