c# - C# 和 XML 选择器
问题描述
不幸的是,我对 C# 一无所知,我只是尝试翻译下面的一段代码。
var body = Document.SelectSingleNode("//soap:Body/*[1]", Manager);
这里选择了哪个元素? 是<ds:KeyInfo>
吗?
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="ED-1B758D26C51BFCD86614340101135852" Type="http://www.w3.org/2001/04/xmlenc#Content">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" wsse11:TokenType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey">
<wsse:Reference URI="#EK-1B758D26C51BFCD86614340101135741"/>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue></xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</soap:Body>
</soap:Envelope>
解决方案
我建议您看一下XPath Syntax,它应该对您有很大帮助。
让我用这个表达式来解释你现在正在使用什么元素//soap:Body/*[1]
:该//
表达式意味着您将采用与选择匹配的节点,在这种情况下,soap:Body
无论它在哪里。该/
表达式告诉您从该节点获取一个子节点。*
通配符匹配任何元素节点,并告诉[1]
它获取第一个子节点。
在这一切之后,你得到的当前节点是xenc:EncryptedData
.
推荐阅读
- arrays - Julia 中的分布式 3 维数组
- javascript - 如何使我的绝对定位元素响应?
- merge - PDF 文件到相应的文件夹
- sql - 选择其中一个重复行并将其他行保持为 NULL SQL Netezza
- azure-pipelines-build-task - 如何创建到我的本地服务的服务连接?
- tensorflow - 没有 Eager 模式的 Tensorflow 提前编译?
- asp.net-web-api - 中介者模式——在控制器中还是在应用程序服务中?[asp.net 网络接口]
- sql - 如何在选择语句中选择结果作为子查询,大小写从 int 到 string
- aws-lambda - 无服务器部署失败:至少需要 ProvisionedThroughput、... 之一
- powerbi - Sportfire 到 Power BI 图表