Access fields in Powershell string containing XML

Viewed 35

How can I access the value of 'b' in the following string?

$x='<xml><obj a="Some" b="values" c="here"/></xml>'

According to Get Attribute of XML Node String in PowerShell I could access the field with

$y=[xml]$x
$y.obj.b

But there is no output.

1 Answers

You skipped the document element.

$y.xml.obj.b

will print "values".

Related