Accessing XElement having namespace inside a parent with different namespace

I am having an xelement like this.

<fiAPI xmlns="" xmlns:ITI="" xmlns:ds="" xmlns:xenc="" xmlns:xsi="" xsi:schemaLocation="">
  <fiHeader Version="2.2">
    <Service Name="" Version="8.0">
            <CipherData xmlns="">
      <MessageDigest algorithm="SHA-1"></MessageDigest>

i am trying to set some value to CipherValue tag like this.

var loginRequestNameSpace  = "";
var cipherDataNameSpace = "";
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 tag reads as NULL. I am doing something wrong with the namespace ?Can anybody help on this ?


You need to use a proper XName to correctly address the elements with different namespaces.

You can use the static method XName.Get("fiHeader", loginRequestNameSpace) for example instead of using string concatenation.

Need Your Help

In capistrano 3, is it possible to bundle & asset precompile locally and copy the results to application server?

ruby-on-rails-4 capistrano bundler capistrano3

At present, I have it setup so that capistrano git pulls the latest code on production servers, bundle installs and asset precompiles it individually on each web server.