且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检索 XML 树值的特定部分

更新时间:2023-02-23 11:20:55

使用 XPath 的答案仍然过时.自从 LINQ to XML 统治所有这些以来,已经十多年了.来吧.

The answer that is using XPath is still archaic. It is already more than a decade since LINQ to XML rules them all. Here we go.

c#

void Main()
{
    XElement xml = XElement.Parse(@"<InitializePagedPull ShowCode=""AR13dfD""><TokenInfo PageToken=""293845657-32-47"" TotalRecords=""1"" PageSize=""20"" TotalPages=""1""/></InitializePagedPull>");
    string pageToken = xml.Descendants().Attributes("PageToken").FirstOrDefault().Value;
}