PowerShell Sql Server Extended Events xml query value in between tags

99 Views Asked by At

Given this sample xml, can anyone help me read the inputbuf?

<deadlock>   
<process-list>    
    <process id="123" taskpriority="123">     
        <inputbuf>  some random string like this   </inputbuf>    
    </process>    
</process-list>   
</deadlock> 

I know that I can read the id & taskpriority like this:

$event.Fields["xml_report"].Value.XML.SelectNodes('//deadlock/process-list/process').id

They both give me "123". But I want the value between the inputbuf tags, I want to read the " some random string like this ". Thanks for your help

1

There are 1 best solutions below

1
On

I do not know how you parse the XML, but usually, there is property InnerText, which contains the text you want. For example, given that your XML is in string variable named $xml, you can use:

$node = $xml | Select-Xml -XPath "/deadlock/process-list/process/inputbuf"

Write-Host $xx.Node.InnerText