使用.NET删除带有冒号的XML节点

时间:2019-09-17 14:45:02

标签: c# .net xml saml

我正在尝试删除带有冒号的XML节点,我的意思是一个名为“ saml:EncryptedAssertion”的节点。我想从saml:EncryptedAssertion删除到/saml:EncryptedAssertion

这是XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Version="2.0" ID="mFCXf3nW6CjpJ81L9Yu" IssueInstant="2019-09-11T13:29:01.254Z" Destination="https://test.com/sso.aspx">
   <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">test.qc.com</saml:Issuer>
   <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
      <ds:SignedInfo>
         <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
         <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
         <ds:Reference URI="#mFCXf3nW6C7tL9Yu">
            <ds:Transforms>
               <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
               <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            </ds:Transforms>
            <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
            <ds:DigestValue>ejzCKbusIE6eZWiMyh07qJB88=</ds:DigestValue>
         </ds:Reference>
      </ds:SignedInfo>
      <ds:SignatureValue>Vzo5APGqy/D4YPqgEpW5kOhV3aDpV6ZH/K0FBonrYFaoDn7eG4rIWoDhJAhdh pas9O70JgqIxi1e6fPLG0zWMCEVDhD0VKK6DPdJeesRxuyqL6ZoQ9oe7FvIsnkGu/QxWVwl2DZZD 73Z/brHijqXg3sRQGsgeZlsnH5JyBj/ADJZgCablLXHBr75wQmZi1AvsLE9e/h3+U7RMalqqx0TI bo8OXA/9ZTdJnF9zWU9hYcFhHBTPF9fGDdsFIg==</ds:SignatureValue>
      <ds:KeyInfo>
         <ds:X509Data>
            <ds:X509Certificate>MIIGojCCBYqgAwIBAgIQCEZjQ1QTXW74RfN6KsynzjANBgkqhkiG9w0BAQsFADBEMQswCQYDVQQG EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMR4wHAYDVQQDExVEaWdpQ2VydCBHbG9iYWwgQ0Eg h5huCoc4zoFHWLdkfDpJzYwjm/rXWfhanaxYlTlYb7ExD09RuUrMS0ahcLt K2nRAx7CD6oLdH6LTCuuZNaaQloK1QBRQWSr5X1Q5v56/VeMVEs8/qd/28y+a4G+Fg==</ds:X509Certificate>
         </ds:X509Data>
         <ds:KeyValue>
            <ds:RSAKeyValue>
               <ds:Modulus>Kxp7D1YCvvDd0WlOqvvrEkuPi1iRBXQLj3xopwKY7INzvwnKykw QxcV+y50B1E+oV8oHD0c+ZTN1NRGWCfFLPoRhIShIG5QaPpQy1h9E74BO2VohQPhkj9hwRC7qTIb pKXztQi0T2BERs/iDxEEHa9xzY0AjBEqvUoZ8iqbd4IoqcF0+ryWwP+rCR9FPy43aW+U0mvYn2KT N+MA0JSdhLrAD9h1KKQIpXnL64W7QDexiJaXUQ==</ds:Modulus>
               <ds:Exponent>AQAB</ds:Exponent>
            </ds:RSAKeyValue>
         </ds:KeyValue>
      </ds:KeyInfo>
   </ds:Signature>
   <samlp:Status>
      <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
   </samlp:Status>
   <saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
      <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Type="http://www.w3.org/2001/04/xmlenc#Element">
         <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
         <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
            <xenc:EncryptedKey>
               <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" />
               <xenc:CipherData>
                  <xenc:CipherValue>aOee YjJK1CC63E1RcD4qKUmrWHDqqGO3RszSMcdWeKDndzlFbj9Z3TsFmVmVQEsL/pryg6nJAYd6jQrC FLzHlTSUKqXxS9Rl9VI=</xenc:CipherValue>
               </xenc:CipherData>
            </xenc:EncryptedKey>
         </ds:KeyInfo>
         <xenc:CipherData>
            <xenc:CipherValue>Pr6BvqheXamo3N1qeqUkEJfbpx0nXYMcQ icqL44JGxy3F8L+z9dWy0EATu+MjKLAtb2F3A6u5VJ/PMUGYJLriqfRb/RI/8FOEsOjJn7hqeXwA 74Kd0D+w7E1mRJYIMlJ+E8OlZYy9ETx9n55infrFElp3b1w9nKwJc38wFksG7s2HBQGDWhmeA1po SDM+5dlam9f9mNf36QTvI4VIQzpguQ62HoFl0k2w5VAyCB5auwMsdp2MYvCOoVXo2S/Ld0LpDaeL DcKlM7w9b4TsuaDhESgGGD+270g0Ub6e0Af8jRi0a0kYy782t4hCF8Ha2xmHeZoOexxt0dIF+pZT w9bLc0Fb6FcNMJ+276MoTII58POamQ==</xenc:CipherValue>
         </xenc:CipherData>
      </xenc:EncryptedData>
   </saml:EncryptedAssertion>
</samlp:Response>

这是我已经尝试过的:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.PreserveWhitespace = true;
xmlDoc.Load("XMLAssertionEncrypted.xml");

XmlNode product = xmlDoc.SelectSingleNode("//saml:EncryptedAssertion");

xmlDoc.RemoveChild(product);

0 个答案:

没有答案
相关问题