【发布时间】:2018-02-16 19:16:28
【问题描述】:
我正在做一些非常简单的事情。我正在尝试从一个小的 XML 文件中检索一个节点。
<?xml version="1.0" encoding="UTF-8" ?>
<SAMLConfiguration xmlns="urn:componentspace:SAML:2.0:configuration">
<IdentityProvider Name="IdpNameInSPForIsuer"
Description="SecureAuth"
LocalCertificateFile=""
LocalCertificatePassword=""/>
<ServiceProviderProfiles>
<ServiceProvider NameIdentifier ="SPIssuerName"
ExpectsSignatureVerification="true"
ExpectsSignedResponse="false"
Certificate="sharedpubliccsert.cer"
DigestMethod="SAMLIdentifiers.DigestMethods.SHA1"
SignatureMethod="SAMLIdentifiers.SignatureMethods.RSA_SHA1"
SingleLogoutServiceUrl="https://serviceprovider/slo"
SendResponseBy="HTTP-Redirect" />
</ServiceProviderProfiles>
</SAMLConfiguration>
我正在尝试获取 ServiceProvider。 下面是我的 C# 代码:
string parent = "ServiceProviderProfiles"; string children = "ServiceProvider";
var nodePath = string.Concat(@"//", parent, @"/", children);
var xmlNode = xmlDocument.SelectSingleNode(nodePath);
当我调试时,xmlNode 为空。我的代码有什么问题导致 xmlNode 为空?
【问题讨论】:
-
您需要使用默认命名空间
xmlns="urn:componentspace:SAML:2.0:configuration"进行搜索,如Using Xpath With Default Namespace in C# 和XmlDocument.SelectSingleNode and xmlNamespace issue 和SelectSingleNode returning null for known good xml node path using XPath 所示。
标签: c# xml xmldocument xmlnode selectsinglenode