Find values under one node in XML

后端 未结 2 1887
执笔经年
执笔经年 2021-01-28 10:47

Below is xml file format from which words to be searched.



Preface


             


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-28 11:46

    I would use Linq2Xml

    XDocument xDoc = XDocument.Parse(xml); //or XDocument.Load(fileName)
    var words = xDoc.Descendants("Word")
                    .Select(w => String.Join("",w.Descendants("Char").Select(c => c.Value)))
                    .ToList();
    

    --EDIT--

    for @Y.Ecarri

    var words2 = xDoc.XPathSelectElements("//Word")
                     .Select(w => String.Join("", w.Elements().Select(c => c.Value)))
                     .ToList();
    

提交回复
热议问题