【问题标题】:C# and XML selectorC# 和 XML 选择器
【发布时间】:2018-08-22 12:17:40
【问题描述】:

不幸的是,我对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>

【问题讨论】:

  • 你尝试的时候发生了什么?
  • 如前所述.. 我不是 C# 开发人员.. 我不能
  • 这与C#无关。它只是 XPath 并选择 的第一个子节点 (
  • @clarkk 试图在我的回答中向您解释。正如 Cetin Basoz 所说,这确实与 C# 无关。

标签: c# xml soap


【解决方案1】:

我建议你看看XPath Syntax,这应该对你有很大帮助。

让我用这个表达式来解释你现在正在使用的元素://soap:Body/*[1]// 表达式意味着您将采用与选择匹配的节点,在这种情况下 soap:Body 无论它在哪里。 / 表达式告诉您从该节点获取一个子节点。 * 通配符匹配任何元素节点,[1] 告诉它获取第一个子节点。

接下来,你得到的当前节点是xenc:EncryptedData

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    相关资源
    最近更新 更多