Je fais quelque chose de très simple. J'essaie de récupérer un noeud à partir d'un petit fichier XML.Sélection d'un nœud 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>
J'essaie d'obtenir le ServiceProvider. Voici le code C# Je:
parent string = "de ServiceProviderProfiles"; chaîne children = "ServiceProvider";
var nodePath = chaîne.Concat (@ "//", parent, @ "/", enfants);
var xmlNode = xmlDocument.SelectSingleNode (nodePath);
Lorsque je débogue, le xmlNode est null. Quels problèmes avec mon code provoquent la nullité du xmlNode?
Vous devez utiliser la recherche en utilisant l'espace de noms par défaut 'xmlns = "urn: componentspace: SAML: 2.0: configuration"' comme indiqué dans [Utilisation xChemin Espace de noms par défaut dans C#] (https://stackoverflow.com/a/585822/3744182) et [XmlDocument.SelectSingleNode et xmlNamespace problème] (https://stackoverflow.com/a/4171468) et [SelectSingleNode renvoyant null pour le chemin de noeud XML xml bien connu en utilisant XPath ] (https://stackoverflow.com/q/1089196/3744182). – dbc
Exemple [violon] (https://dotnetfiddle.net/py0mfe) en utilisant [Utiliser Xpath avec l'espace de noms par défaut en C#] (https://stackoverflow.com/a/585822/3744182). – dbc