parsing XML content - C#

前端 未结 6 1477
轮回少年
轮回少年 2021-01-21 00:40

I have not used XML for very long and need to extract the useful information from an XML response. If there are 2 tags that are the same but have a different name e.g



        
6条回答
  •  旧时难觅i
    2021-01-21 00:57

    You can do it with LINQ to XML:

    var doc = XDocument.Load("YourXMLPath.xml");
    var content = doc
    .Element("lst")
    .Elements("lst")
    .Where(e=>((string) e.Attribute("name") ?? "")=="overflow")
    .Select(e=>e.Element("str").InnerText())
    .FirstOrDefault();
    

提交回复
热议问题