Say I have the following xml
Gambardella, Matthew
You could filter the books using Where-Object
, or you could try XPath. Here's two examples:
Dot-navigation
$bookid = 'bk102'
$myxml = [xml](Get-Content '.\New Text Document.txt')
$node = $myxml.catalog.book | Where-Object { $_.id -eq $bookid }
$node
id author
-- ------
bk102 Ralls, Kim
XPath
$bookid = 'bk102'
$myxml = [xml](Get-Content '.\New Text Document.txt')
$node = $myxml.SelectSingleNode("catalog/book[@id='$bookid']")
$node
id author
-- ------
bk102 Ralls, Kim