gilles27
gilles27

Reputation: 2241

How do I XPath to attribute whose namespace is different to its ancestor's

I'm trying to query the codebase attribute on line 11 of this XML file.

<?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>

It need to be something along the lines of /assembly/deployment/deploymentProvider/@codebase but the namespace prefixes need to be accounted for. The deployment element is possibly causing the problem as it's not in the asmv1 namespace like its ancestors.

Can anyone provide an xpath to the codebase attribute?

Upvotes: 1

Views: 344

Answers (1)

forty-two
forty-two

Reputation: 12817

You didn't give us the details of in what context you will use the XPath expression, but generally:

  1. Map asmv1 to urn:schemas-microsoft-com:asm.v1
  2. Map asmv2 to urn:schemas-microsoft-com:asm.v2

then this expression will get you what you want:

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

Upvotes: 2

Related Questions