如何将XPath归属于其名称空间与其祖先不同的属性

时间:2013-05-09 16:40:51

标签: xml xpath

我正在尝试查询此XML文件第11行的codebase属性。

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
    <assemblyIdentity name="VcilApp.application" version="0.0.0.0" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
    <description asmv2:publisher="VCIL" asmv2:product="VcilApp" xmlns="urn:schemas-microsoft-com:asm.v1" />
    <deployment install="true" minimumRequiredVersion="0.0.0.0" co.v1:createDesktopShortcut="true">
        <subscription>
            <update>
                <beforeApplicationStartup />
            </update>
        </subscription>
        <deploymentProvider codebase="file://vandc/vcfileshare/VC Apps/Dialler/VcilApp.application" />
    </deployment>
    <compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2">
        <framework targetVersion="4.5" profile="Full" supportedRuntime="4.0.30319" />
    </compatibleFrameworks>
    <dependency>
        <dependentAssembly dependencyType="install" codebase="Application Files\VcilApp_3_0_9_2705\VcilApp.exe.manifest" size="26738">
            <assemblyIdentity name="VcilApp.exe" version="0.0.0.0" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
            <hash>
                <dsig:Transforms>
                    <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
                </dsig:Transforms>
                <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
                <dsig:DigestValue>7ikkD3Ls5FCfLulntbYd54jZwk/4L5dnNZ4rGBZELB8=</dsig:DigestValue>
            </hash>
        </dependentAssembly>
    </dependency>
</asmv1:assembly>

它需要与/ assembly / deployment / deploymentProvider / @ codebase一致,但需要考虑名称空间前缀。部署元素可能会导致问题,因为它不像asmv1名称空间那样位于asmv1名称空间中。

任何人都可以为codebase属性提供xpath吗?

1 个答案:

答案 0 :(得分:2)

您没有向我们提供有关您将使用XPath表达式的上下文的详细信息,但通常是:

  1. asmv1映射到urn:schemas-microsoft-com:asm.v1
  2. asmv2映射到urn:schemas-microsoft-com:asm.v2
  3. 然后这个表达式可以得到你想要的东西:

    /asmv1:assembly/asmv2:deployment/asmv2:deploymentProvider/@codebase