I am trying to fetch all the XML nodes, where Attribute “Tag” value is “Fetch” with a XPath, without looping much using PowerShell 5.1. Please help.
[xml] $XMLValue=@'
<Root>
<Child>
<Parameter Tag="Fetch"><![CDATA["Data"]]></Parameter>
<Parameter Tag="DontFetch"><![CDATA["Data"]]></Parameter>
</Child>
<Child>
<Test>
<Node Tag="Fetch"><![CDATA["Data"]]></Parameter>
<Node Tag="DontFetch"><![CDATA["Data"]]></Parameter>
</Test>
</Child>
<Child>
<Test>
<Test1>
<Node1 Tag="Fetch"><![CDATA["Data"]]></Parameter>
<Node2 Tag="DontFetch"><![CDATA["Data"]]></Parameter>
</Test1>
</Test>
</Child>
</Root>
'@
roberth
February 13, 2020, 6:07am
2
I’m sorry, but your example is completely blank. Give it another whirl, or maybe upload it as a Gist for easier reading
js2010
February 13, 2020, 7:13am
3
Like this? Xpath is case sensitive.
select-xml "//*[@Tag='Fetch']" file.xml
Node Path Pattern
---- ---- -------
Parameter /Users/js/foo/file.xml //*[@Tag='Fetch']
Node /Users/js/foo/file.xml //*[@Tag='Fetch']
Node1 /Users/js/foo/file.xml //*[@Tag='Fetch']
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
js2010
February 13, 2020, 1:24pm
4
I didn’t think xml would post here at all. You have several errors in the xml where you mix up “Node” and “Parameter”. I edited my answer to match the case.