Not able to understand why my simple xpath does not work on the below XML.
I need to find the node "deployment" and delete the childnode and then add a new child node. Should be pretty easy, but no, there is something with the XML that makes it not possible for my code to find the deployment-node by simply selecting it by its name.
The XML (Clickonce .Net XML)
<?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="PublishDev.app" version="3.1.0.182" publicKeyToken="38f29cb66cf790f2" language="neutral" processorArchitecture="x86" xmlns="urn:schemas-microsoft-com:asm.v1" />
<description asmv2:publisher="KLP" asmv2:product="PublishDev" xmlns="urn:schemas-microsoft-com:asm.v1" />
<deployment install="true">
<subscription>
<update>
<expiration maximumAge="0" unit="days" />
</update>
</subscription>
<deploymentProvider codebase="http://nrs.dev/NrsClient/PublishDev.application" />
</deployment>
<compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2">
<framework targetVersion="4.7" profile="Client" supportedRuntime="4.0.30319" />
<framework targetVersion="4.7" profile="Full" supportedRuntime="4.0.30319" />
</compatibleFrameworks>
<dependency>
<dependentAssembly dependencyType="install" codebase="ApplicationFiles\PublishDev_3_1_0_182\PublishDev.exe.manifest" size="48466">
<assemblyIdentity name="PublishDev.exe" version="3.1.0.182" publicKeyToken="38f29cb66cf790f2" language="neutral" processorArchitecture="x86" 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#sha1" />
<dsig:DigestValue>zbbwOLiL12PznwEX7G3FGhmU8R0=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
</asmv1:assembly>
Then to loop the XML using Powershell
function loopXml{
param(
$nodes
)
write-host "************************* Loop my xml********************* "
foreach ($node in $nodes) {
Write-host $node.toString()
}
}
$deployManifestFullPath = "D:\temp\stripped.xml"
$sourcexml = [xml](get-content $deployManifestFullPath);
$nodes = $sourcexml.SelectNodes("deployment")
loopXml $nodes
$nodes = $sourcexml.SelectNodes("//*", $ns)
loopXml $nodes
The output
************************* Loop my xml*********************
************************* Loop my xml*********************
assembly
assemblyIdentity
description
deployment
subscription
update
expiration
deploymentProvider
compatibleFrameworks
framework
framework
dependency
dependentAssembly
assemblyIdentity
hash
Transforms
Transform
DigestMethod
DigestValue
I do not understand why the line
$nodes = $sourcexml.SelectNodes("deployment")
does not return the deployment-node. When I select the whole document it is there, but ... well, need some help to figure out this one.
Ref. w3schools XPath Syntax just adding the name of the node should select all nodes with that name. In my case, the single node named deployment.