C# 访问在具有不同命名空间的父级中具有命名空间的XElement

C# 访问在具有不同命名空间的父级中具有命名空间的XElement,c#,xml,xml-parsing,linq-to-xml,C#,Xml,Xml Parsing,Linq To Xml,我有一个像这样的问题 <fiAPI xmlns="http://integration.fiapi.com" xmlns:ITI="http://www.ITIWnet.com/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xenc="http://www.w3.org/2001/xmlenc#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLo

我有一个像这样的问题

<fiAPI xmlns="http://integration.fiapi.com" xmlns:ITI="http://www.ITIWnet.com/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xenc="http://www.w3.org/2001/xmlenc#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://integration.fiapi.com/fiAPI.xsd">
  <fiHeader Version="2.2">
    <Service Name="" Version="8.0">
      <DateTime>2015-04-23T16:09:39-05:00</DateTime>
      <UUID>d111bc1b-e539-47e6-93e0-d1c426346b78</UUID>
    </Service>
    <Security>
      <AuthenticationMaterial>
        <PrincipalPWD>
          <EncryptedData>
            <CipherData xmlns="http://www.w3.org/2001/04/xmlenc#">
              <CipherValue></CipherValue>
            </CipherData>
          </EncryptedData>
        </PrincipalPWD>
      </AuthenticationMaterial>
      <PrincipalID></PrincipalID>
      <TrustRelationship>User</TrustRelationship>
      <MessageDigest algorithm="SHA-1"></MessageDigest>
    </Security>
  </fiHeader>
</fiAPI>
var loginRequestNameSpace  = "http://integration.fiapi.com";
var cipherDataNameSpace = "http://www.w3.org/2001/04/xmlenc#";
XElement encryptedDataElement = loginRequestElement.Element(loginRequestNameSpace + "fiHeader").Element(loginRequestNameSpace + "Security").Element(loginRequestNameSpace + "AuthenticationMaterial").Element(loginRequestNameSpace + "PrincipalPWD").Element(loginRequestNameSpace + "EncryptedData");
XElement cypherDataElement = encryptedDataElement.Element(cipherDataNameSpace + "CipherData");

CipherData标记读取为空。我的名称空间有问题吗?有人能帮忙吗?

您需要使用适当的
XName
来正确处理具有不同名称空间的元素

例如,您可以使用静态方法
XName.Get(“fiHeader”,loginRequestNameSpace)
而不是使用字符串连接