In Silverlight 3.0 XmlDocument is no more. Instead, we have to use XDocument, XElement, XAttribute from System.Xml.Linq namespace.

It can be used in combination with linq, so here is how to parse a very simple xml-file:

<?xml version=\”1.0\”?>
<retval>
<command>0</command>
<verb>1</verb>
<verb2>2</verb2>
</retval>

Approach 1:

use a combination of Linq, and a traditional foreach-Loop:

//read string containing xml-file
XDocument xd = XDocument.Parse(xmlfile);
//get all retval-nodes (allthough it’s just 1)
var commands = from cmd in xd.Descendants(“retval”)
select cmd;
//loop through retval-nodes (still only 1)
foreach (var cmd in commands)
{
//get collection of childnodes
var objects = cmd.Nodes();
//parse command, verb, verb1
foreach (XElement elem in objects)
{
string n = elem.Name.ToString();
string v = elem.Value;
}
}

//read string containing xml-file
XDocument xd = XDocument.Parse(xmlfile);
//get all retval-nodes (allthough it’s just 1)
var commands = from cmd in xd.Descendants(“retval”)
select cmd;

//loop through retval-nodes (still only 1)
foreach (var cmd in commands)
{
//get collection of childnodes
var objects = cmd.Nodes();
//parse command, verb, verb1
foreach (XElement elem in objects)
{
string n = elem.Name.ToString();
string v = elem.Value;
}
}

The second approach is using Linq in combination with lambda-expressions, which results in a List<string>. containing the values only:

var doc = XDocument.Parse(“<retval><command>1</command><verb>2</verb><verb2>3</verb2></retval>”);
var values = doc.Descendants(“retval”).Descendants().Select(i => i.Value).ToList();

( .. to be continued ..)