PowerShell has dot syntax for accessing some XML nodes:
root.object1.object2
Is it possible to do something like this?
root.object1.object2[@id="pdt1"]
except this syntax doesn't work.
Does this kind of syntax exist or is it mandatory to use SelectNodes()
method?
No, you can't mix object and XPath syntax like that. Either use XPath:
$xml.SelectSingleNode('/root/object1/object2[@id="pdt1"]')
or use object syntax with a Where-Object
filter (as suggested by @PetSerAl in the comments to your question):
$xml.root.object1.object2 | Where-Object { $_.id -eq 'pdt1' }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With