Parsing specifc information from a specific node in XML file

Tagged: ,

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Long S Long S 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #38292
    Profile photo of Long S
    Long S
    Participant

    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.

    #38294
    Profile photo of Jonathan Warnken
    Jonathan Warnken
    Participant

    Try this

    $book= $xmldata.catalog.book| where {$_.title -eq $bookname } |Select-Object id
    
    #38295
    Profile photo of Long S
    Long S
    Participant

    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
    }

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.