- Home /
How to load this XML File?
I have a testing xml file and I want to read in the app.
But I don't know how to read this xml
<?xml version="1.0" encoding="UTF-8" ?>
<thisXml>
<system systemLanguage = "English">
<item0 imageText = "aaaaaaaaa" imageRectX = "0" imageRectY = "0" imageUrl="http://www.blog.spoongraphics.co.uk/wp-content/uploads/2009/apple-wallpaper/320x480.jpg"/>
<item1 imageText = "aaaaaaaaa" imageRectX = "0" imageRectY = "50" imageUrl="http://testsuites.opera.com/object-fit/support/160x240.ogv.png"/>
<item2 imageText = "bbbbbbbbb" imageRectX = "0" imageRectY = "0" imageUrl="http://www.blog.spoongraphics.co.uk/wp-content/uploads/2009/apple-wallpaper/320x480.jpg"/>
<item3 imageText = "bbbbbbbbb" imageRectX = "0" imageRectY = "50" imageUrl="http://testsuites.opera.com/object-fit/support/160x240.ogv.png"/>
</system>
<system systemLanguage = "中文">
<item0 imageText = "你好" imageRectX = "0" imageRectY = "0" imageUrl="http://www.blog.spoongraphics.co.uk/wp-content/uploads/2009/apple-wallpaper/320x480.jpg"/>
<item1 imageText = "你們" imageRectX = "0" imageRectY = "50" imageUrl="http://testsuites.opera.com/object-fit/support/160x240.ogv.png"/>
<item2 imageText = "我很好" imageRectX = "0" imageRectY = "0" imageUrl="http://www.blog.spoongraphics.co.uk/wp-content/uploads/2009/apple-wallpaper/320x480.jpg"/>
<item3 imageText = "我們" imageRectX = "0" imageRectY = "50" imageUrl="http://testsuites.opera.com/object-fit/support/160x240.ogv.png"/>
</system>
</thisXml>
Can help me? Thanks!
Answer by DaveA · Aug 23, 2011 at 12:20 AM
You could just open it as text with System.IO functions or WWW.data and parse out what you need using standard String methods to search it. If you really want an XML parse, try http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx
something like (untested)
xml = new XmlDocument(); xml.LoadXml(text); // returned by www for example
var languageCount : int = xml.ChildNodes.Count; for (var i : int = 1; i < cnodeCount; i++) { var langNode : XmlNode = xml.ChildNodes.Item(i); var itemCount : int = langNode.ChildNodes.Count; for (var j : int = 0; j < itemCount; j++) { var itemNode : XmlNode = langNode.Item(j); var imgText : String = itemNode.Attributes["imageText"].Value; var imageRectX : int = parseInt(itemNode.Attributes["imageRectX"].Value); .. etc .. .. do something with that.. } }
Your answer

Follow this Question
Related Questions
Declaring XML Namespace at Runtime 1 Answer
Using JSON to get tree data into JavaScript objects 3 Answers
Item/Database Error 2 Answers
Easy XML Parsing 4 Answers
Player touch item? 3 Answers