0

I have three nodes with the same name but with different attributes. I would like to only select the one where the bar attribute exists.

<Test foo="Hello" />
<Test bar="World" />
<Test zed="Goodbye" />

1 Answer 1

2

You could use XPath for this:

Select-Xml -Path path\to\file.xml -XPath '//Test[@bar]'

//Test will resolve any <Test> nodes anywhere in the tree, [@bar] filters them by whether they have a bar attribute or not

Sign up to request clarification or add additional context in comments.

1 Comment

The OP requests for @bar. So in this example it should be: //Test[@bar]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.