[英]C# and XML selector
不幸的是,我对 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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.