# read in an xml server from Unity3D 4.xx [closed]

I need examples of how to read an xml from a server, using Unity3D..

I think it's something like this.. but I can not retrieve the information from the nodes..

An example would be of great help.. thank you..

var url = "http://server.com/test2.xml";

var www : WWW = new WWW (url); yield www;

var xml : XmlDocument = new XmlDocument();

## closed as off-topic by Anko, MichaelHouse♦Apr 7 '14 at 15:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – MichaelHouse
If this question can be reworded to fit the rules in the help center, please edit the question.

In case you are using C#, you can use the XML classes from .NET. I tend to use the XPathNavigator, since most of the time you need only to read out data, and don't have to write data back.

Snippet from my actual code:

XPathDocument xmlFile;

try {
xmlFile = new XPathDocument (filePath);
} catch (FileNotFoundException ex) {
UnityEngine.Debug.LogException (ex);
}

// Create the navigator to navigate the file
XPathNavigator xnav = xmlFile.CreateNavigator ();

// Get the values of single nodes directly by using their XPath
string viewmode = xnav.SelectSingleNode ("/trainingSettings/viewmode").Value;
int NoItems = xnav.SelectSingleNode ("/trainingSettings/difficulty/noitems").ValueAsInt;
int NoOverallItems = xnav.SelectSingleNode ("/trainingSettings/difficulty/nooverallitems").ValueAsInt;

// Convert values using XmlConvert …
TimeSpan RemainingDurationOfTraining = XmlConvert.ToTimeSpan (xnav.SelectSingleNode ("/trainingSettings/trainingDuration").Value);


By using XPathNavigator.Select(), you can get a list of nodes back and then iterate over them, if necessary.

• Thanks for the example, I'll have to start programming in c # this part, the same code to use for Json?. – blese Mar 4 '14 at 20:30
• Also available, System.XmlReader – Seth Battin Apr 4 '14 at 17:18