[C#][Tips][File] XML:属性値リスト


public static void mRead_SelectNodes_Attrs()
{
    List<string>  slValue = new List<string> ();

    /* File */
    var xDoc = new System.Xml.XmlDocument();
    xDoc.Load(@"D:\CustomersOrdwes.xml");

    /* Node(List) */
    string sXPath = @"/Root/Customers/Customer";
    System.Xml.XmlNodeList xNodeList = xDoc.SelectNodes(sXPath);

    /* Element-Attribute */
    string sAttrName = "CustomerID";
    foreach (System.Xml.XmlNode item in xNodeList)
    {
        foreach (System.Xml.XmlNode item_Attr in item.Attributes)
        {
            if (item_Attr.Name == sAttrName) slValue.Add((string)item_Attr.Value);
        }

    }

    /*  */
    slValue.ForEach(c => Console.WriteLine(c));

}