有多种方法可以做到这一点。
这是示例代码
// xmlns attribute from the root
XNamespace ns = "urn:componentspace:SAML:2.0:configuration";
// read XML file into XmlDocument
XDocument doc = XDocument.Load("file.xml");
// Select XML descendants with Linq
var result = doc.Descendants(ns + "SAMLConfiguration").Descendants().Where(c => c.Name.LocalName.ToString() == "ServiceProvider")
.ToArray();