score:1

If you are trying to iterate on all your controls in the XML and retreive the info, you should use XPath.

Here is an example:

XPathDocument Doc = new XPathDocument("yourfile.xml");
XPathNavigator navigator = Doc.CreateNavigator();
XPathNodeIterator iterator = navigator.Select("/controls/*");
while (iterator.MoveNext())
{
    System.Diagnostics.Debug.Print(iterator.Current.Content);
    System.Diagnostics.Debug.Print(iterator.Current.Location);
}

score:2

Using LINQ: (For ForeColor/LinkColor check for null)

XDocument loaded = XDocument.Load(@"C:\XMLFile1.xml");

            var q = from c in loaded.Descendants().Descendants()
                            select new
                            {
                                content = c.Attribute("Content"),
                                location = c.Attribute("Location"),
                                size = c.Attribute("Size"),
                                foreColor = c.Attribute("ForeColor"),
                                linkColor = c.Attribute("LinkColor")
                            };

            foreach (var controlItem in q)
                Console.WriteLine("Control content = {0}", controlItem.content);

Related Articles