Get the value between <> with dynamic number inside it

前端 未结 2 719
慢半拍i
慢半拍i 2021-01-15 19:25

I am working on a text summarization method ,for test my method i have a benchmark called doc 2007 ,inside this benchmark i have a lot of xml file ,i should cle

2条回答
  •  情书的邮戳
    2021-01-15 20:10

    Using LINQ to XML should be easier:

    var res = XElement.Parse(xml)
                      .Descendants("sentence").Where(e => e.Attribute("id").Value == "s0")
                      .FirstOrDefault().Value;
    

    or, as Yeldar suggested, the cleaner way would be:

    var s0 = XElement.Parse(xml)
                     .Descendants("sentence").FirstOrDefault(e => e.Attribute("id").Value == "s0")
                     .Value;
    

提交回复
热议问题