Get nodes from xml files

前端 未结 3 499
失恋的感觉
失恋的感觉 2020-12-06 13:23

How to parse the xml file?


 
<         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 13:52

    I would definitely use LINQ to XML instead of the older XmlDocument based XML API. You can accomplish what you are looking to do using the following code. Notice, I changed the name of the element that I am trying to get the value of to 'loc' and 'lastmod', because this is what is in your sample XML ('name' and 'url' did not exist):

    XElement element = XElement.Parse(XMLFILE);
            IEnumerable list = element.Elements("sitemap");
            foreach (XElement e in list)
            {
                String LOC= e.Element("loc").Value;
                String LASTMOD = e.Element("lastmod").Value;
            }
    

提交回复
热议问题