1

I have this following XML that I need to read the attributes dynamically however I am stuck in finding the correct way to do it in PS:

<DataGroups>
  <Category1 Identifier="Project789">
  <Category2 Identifier="Project234">
  <SimpleCategory56 Identifier="Project56">
  ......
</DataGroups>  

I have tried the following till now which works however how do I do this dynamically??

$xml = [xml](get-content $Path)
$test = $xml.DataGroups.Category1.Identifier

I have also tried doing something this:

$xml = [xml](get-content $Path)
Select-Xml -Xml $xml -XPath "//Category1/@Identifier"

but then I am getting somwthing cryptic like the following:

Node       Path        Pattern
----       ----        -------
Identifier InputStream //Category1/@Identifier

1 Answer 1

1

You were on the right track. You had to simply try this in the Select-Xml:

$xml = [xml](get-content $Path)
(Select-Xml -Xml $xml -XPath "//./@Identifier").Node.Value

Please try and let me know. It should return

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

Comments

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.