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);
以上两条语句给出的值是 4500。
但我不想使用翻译,只想直接使用它来获取值。
看来 != 在下面不起作用,并且没有获取值并导致 null 。
这是我试图实现但不起作用的新 Xpath。
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";
我怎样才能达到同样的效果?
最佳答案
这样做的原因是 !=
要求该属性存在,而如果缺少该属性,translate
也会产生结果。
您需要使用not()
来代替:
.../acord:TechAccountAmtItem[not(@Type = 'ipt') and not(@AmtStatus = 'informational')]/...
这假设 Type
也可能丢失。如果没有,您可以使用 @Type != 'ipt'
代替。
关于c# - XPath 不适用于 SelectSingleNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47925166/