Q:

Select node from XML

I new to xml and a litlle confused.
I have next xml
<Data>
    <seo>
        <Title>
            <ID>Site_Title</ID>
            <name>A Media</name>
        </Title>

        <Keywords>
            <ID>Keywords</ID>
            <name>A, Media, keywords</name>
        </Keywords>

        <Site_Description>
            <ID>Site_Description</ID>
            <name>A Media site description</name>
        </Site_Description>
    </seo>

    <main_slider>
        <slider1>
            <id></id>
            <image_url></image_url>
            <text></text>
            <btn_text></btn_text>
            <btn_link></btn_link>
        </slider1>

        <slider2>
            <id></id>
            <image_url></image_url>
            <text></text>
            <btn_text></btn_text>
            <btn_link></btn_link>
        </slider2>

        <slider3>
            <id></id>
            <image_url></image_url>
            <text></text>
            <btn_text></btn_text>
            <btn_link></btn_link>
        </slider3>

        <slider4>
            <id></id>
            <image_url></image_url>
            <text></text>
            <btn_text></btn_text>
            <btn_link></btn_link>
        </slider4>

        <slider5>
            <id></id>
            <image_url></image_url>
            <text></text>
            <btn_text></btn_text>
            <btn_link></btn_link>
        </slider5>

    </main_slider>

</Data>

Masterpage.cs
   XmlDocument doc = new XmlDocument();

   doc.Load(Path.Combine(Request.PhysicalApplicationPath, "App_Data/A_data.xml"));

Ok, how from here i can continue? lets say i have next code:
    Page.Title = title_str; // Title set
    Page.MetaDescription = description; // Description set
    Page.MetaKeywords = keywords; // Keywords set

How i get the title > name node from xml? and keywords > name and so on...
It must done only via "foreach" ? anyway, how?

A:

Use Linq to Xml:
var path = Path.Combine(Request.PhysicalApplicationPath, "App_Data/A_data.xml");
XDocument xdoc = XDocument.Load(path);
var seo = xdoc.Root.Element("seo");
Page.Title = (string)seo.Element("Title").Element("name");
Page.MetaDescription = (string)seo.Element("Site_Description").Element("name");
Page.MetaKeywords = (string)seo.Element("Keywords").Element("name");
// etc

Also I suggest you to take a look on LINQ to XML Samples to understand how to use it in future.
You can also use xpath (it's better option, if some some element could be missing):
Page.Title = (string)xdoc.XPathSelectElement("Data/seo/Title/name");

