Author Posts

April 27, 2016 at 5:31 am

I have a xml built like

https://msdn.microsoft.com/en-us/library/windows/desktop/ms762271(v=vs.85).aspx

I am prompting the user to enter a book name and it will return the bookname and author

[xml]$xmldata = Get-Content "books.xml"

$bookname = Read-Host "Please enter Book Name"
$book= $xmldata.catalog.book| where {$_.id -eq $bookname } |`Foreach{

$xmldata.catalog.book.id
}

It will not give me an output. Any help is appreciated.

April 27, 2016 at 6:00 am

Try this

$book= $xmldata.catalog.book| where {$_.title -eq $bookname } |Select-Object id

April 27, 2016 at 6:22 am

That didn't work for me. I figured it out.
I ended up using

[xml]$xmldata = Get-Content "books.xml"

$bookname = Read-Host "Please enter Book Name"
$book= $xmldata.catalog.book| where {$_.id -eq $bookname } |`Foreach{

$_.id
$_.title
}