XMl 在 Windows Phone 中搜索和过滤
本文关键字:搜索 过滤 Phone Windows XMl | 更新日期: 2023-09-27 17:57:15
<?xml version="1.0" encoding="UTF-8"?>
<root>
<player>
<playerId>1234</playerId>
<playerName>ABCD</playerName>
<line>
<studentId>5612</studentId>
<studentName>WXYZ</studentName>
</line>
</player>
</root>
上面显示的是我的 XML,
我必须使用过滤器"玩家姓名"显示XML中的"学生姓名"那么,我应该怎么做呢?谢谢!
您可以使用
LINQ2XML。试试这个:
string xml = @"<?xml version='1.0' encoding='UTF-8'?>
<root>
<player>
<playerId>1234</playerId>
<playerName>ABCD</playerName>
<line>
<studentId>5612</studentId>
<studentName>WXYZ</studentName>
</line>
</player>
</root>";
var doc = XDocument.Parse(xml);
string studentName = (string)doc.Descendants("player")
.Where(p => (string)p.Element("playerName") == "ABCD")
.Descendants("studentName").First();
看起来有一些 LINQ 到 XML 的机会
有关示例,请参阅此处和此处的参考文献。