XML : Picking an element from XML node using a given text

  <?xml version="1.0"?>  <Root>    <Book>      <Name>Title1</Name>      <Name>Title2</Name>      <Name>Title3</Name>    </Book>  </Root>    

I would like to select a specific element from Book node and store it in a variable (so that I can access the InnerText of that element at later point in PowerShell script). I tried following approach but it returns all elements. What would be the right way to select the child element using given text (ex. Title1).

  $item = $xml.SelectSingleNode("//Book/[Name='Title1'])    

Thanks.

No comments:

Post a Comment