powershell find dynamic variables within xml


powershell find dynamic variables within xml



I have performed a web request that returns $xml.
Write-Host $xml.status.audio.volume outputs 56 as it should. Thus I know the XML is OK.


$xml


Write-Host $xml.status.audio.volume



Then I read a file to determine what XML attributes I need to look at:



How do I use that attribute (eg. status.audio.volume) to output or test if the $xml has the value I expect?


status.audio.volume


$xml



e.g. (pseudocode) If $xstatus.status.audio.volume = 56 Then ...


If $xstatus.status.audio.volume = 56 Then ...





Have you tried Compare-Object?
– TheMadTechnician
Jun 28 at 23:45


Compare-Object





I guess I am not explaining correctly. I can hard code something like if $xstatus.status.audio.volume = 56 and that would work, but I need to read the attribute part from a file "status.audio.volume". Then somehow need to concatenate if to $xstatus so I can perform the validation that 56 exists for that attribute.
– user10008227
Jun 29 at 0:01






$xml.SelectSingleNode('status/audio/volume')."#text" ; replace the . with / in the text you read from the file, to make it a valid XPath expression.
– TessellatingHeckler
Jun 29 at 1:29


$xml.SelectSingleNode('status/audio/volume')."#text"


.


/





Thank you. Seems to work with a beginning /.
– user10008227
Jun 29 at 1:43










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV