XPath not working with SelectSingleNode

169 Views Asked by At
private const string TECHACCOUNTAMTITEM_AMT_XPATH = @"//Part[translate(@Type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'instalment']/acord:Jv-Ins-Reinsurance/acord:TechAccount/acord:Subaccount/acord:TechAccountAmtItem[translate(@Type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') != 'ipt' and translate(@AmtStatus, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') != 'informational']/acord:Amt";

var xmlNamespaceManager = this._namespaceManager.GetNamespaceManager(this.TransactionPayload.OuterXml);
                var techAccountAmtItemAmt = Decimal.Parse(this.TransactionPayload.SelectSingleNode(TECHACCOUNTAMTITEM_AMT_XPATH, xmlNamespaceManager).InnerText);

The above two statement gives out the value 4500.

But i dont want to use translate and just want to use it directly to fetech the value .

It seems that != is not working in the below and not fetching the value and resulting in null .

Here is the new Xpath i m trying to achieve but not working .

private const string TECHACCOUNTAMTITEM_AMT_XPATH = @"//Part[@Type = 'Instalment']/acord:Jv-Ins-Reinsurance/acord:TechAccount/acord:Subaccount/acord:TechAccountAmtItem[@Type != 'ipt' and @AmtStatus != 'informational']/acord:Amt";

How can I acheive the same ?

1

There are 1 best solutions below

1
On BEST ANSWER

The reason for this is that != requires the attribute to exist, while translate will also produce a result if the attribute is missing.

You need to use not() instead:

.../acord:‌​TechAccountAmtItem[not(@‌​Type = 'ipt') and not(@AmtStatus = 'informational')]/...

This assumes that Type could be missing as well. If not, you can use @Type != 'ipt' instead.