xpath - 如何在节点测试中选择本地名称

标签 xpath namespaces

我正在尝试对节点 businessEntity 进行数字签名。我在我的转换中使用 Xpath 来引用这个节点。

我的 Xpath 表达式是:

ancestor-or-self::ns1:businessEntity[
   @businessKey = 'uddi:testSignedProviderlastime'
] and not(ancestor-or-self::ns1:businessService)
  and not(ancestor-or-self::ds:Signature)

我想删除命名空间前缀 ns1 的依赖项。有没有办法做到这一点?或者有什么方法可以在我的表达式中指定命名空间 URI。

我已经尝试用 a 替换命名空间前缀 ns1 ,但是使用“”前缀时出错。
感谢您对修改此表达式的任何帮助。

谢谢,
索尼娅

以下是 xml,我也在应用此转换:
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <ns1:save_business xmlns:ns1="urn:uddi-org:api_v3">
        <ns1:authInfo>something
        </ns1:authInfo>
        <ns1:businessEntity businessKey="uddi:testSignedProviderlastime" xmlns:ns1="urn:uddi-org:api_v3">
            <ns1:name>testSignedProviderlastime</ns1:name>
            <ns1:description>Not Provided</ns1:description>
            <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                <ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                    <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
                    <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
                    <ds:Reference URI="" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                        <ds:Transforms xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                            <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
                            <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                                <ds:XPath xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ns1="urn:uddi-org:api_v3">ancestor-or-self::ns1:businessEntity[@businessKey='uddi:testSignedProviderlastime'] and not (ancestor-or-self::ns1:businessService) and not (ancestor-or-self::ds:Signature)</ds:XPath>
                            </ds:Transform>
                        </ds:Transforms>
                        <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
                        <ds:DigestValue xmlns:ds="http://www.w3.org/2000/09/xmldsig#">something</ds:DigestValue>
                    </ds:Reference>
                </ds:SignedInfo>
                <ds:SignatureValue xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                something
                </ds:SignatureValue>
                <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                    <ds:X509Data xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                        <ds:X509Certificate xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                        something
                        </ds:X509Certificate>
                    </ds:X509Data>
                    <ds:KeyValue xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                        <ds:RSAKeyValue xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                            <ds:Modulus xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                            something
                            </ds:Modulus>
                            <ds:Exponent xmlns:ds="http://www.w3.org/2000/09/xmldsig#">AQAB</ds:Exponent>
                        </ds:RSAKeyValue>
                    </ds:KeyValue>
                </ds:KeyInfo>
            </ds:Signature>
        </ns1:businessEntity>
    </ns1:save_business>
</soapenv:Body>

最佳答案

我猜你想要这个:

ancestor-or-self::*[local-name() = 'businessEntity']

或者更精确的:
ancestor-or-self::*
    [local-name() = 'businessEntity' and namespace-uri() = 'urn:uddi-org:api_v3']

关于xpath - 如何在节点测试中选择本地名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5170646/

相关文章:

c++ - 如何在命名空间中应用名称查找

visual-c++ - 在 C++/CLI 中嵌套命名空间

php - SimpleXML文档上的xpath查询-未定义偏移量:0

sql - 通过sql查询读取xml

java - 使用 JAVA 使用 XPATH 将 xml 值存储为 Map

Java、XPath 表达式读取所有节点名称、节点值和属性

xml - 从包含 CDATA 标记的 SOAPUI 中的 XML 响应中检索节点值

r - 如何导入 .R 文件并为其指定别名?就像 import myfile.R as mf

vb.net 创建和使用命名空间

c# - 将项目转换为 VS 2010 时的命名空间错误