2015-12-01 71 views
0

我有一个这样的xelement。访问具有不同名称空间的父项内具有名称空间的XElement

<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> 

我想设置一些值到这样的CipherValue标记。

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标签读取为NULL。我在命名空间上做错了什么?有人可以帮忙吗?

回答

0

您需要使用正确的XName才能正确地寻址具有不同名称空间的元素。

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

相关问题