creating DropdownList

后端 未结 2 1436
刺人心
刺人心 2021-01-29 02:08

Consider the following XML file:

   
            
              
             


        
2条回答
  •  梦如初夏
    2021-01-29 02:35

    Load the xml into an XElement:

            var xml = XElement.Load("test.xml");
    

    Execute XPath to select the SN elements in the cats with id computer: (+ put them in a list)

            var snValues = xml.XPathSelectElements("//cat[@id='computer']/item/SN")
                            .Select(x => x.Value).ToList();
    

    Required usings:

            using System.Linq;
            using System.Xml.Linq;
            using System.Xml.XPath;
    

提交回复
热议问题