Selecting attributes in xml using xpath in powershell

后端 未结 4 2063
醉梦人生
醉梦人生 2020-12-15 06:48

I am trying to use powershell and XPath to select the name attribute shown in the below xml example.

     $xml_peoples= $file.SelectNodes(\"//people\") 
             


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 07:26

    For anyone that has to work around Select-Xml's garbage namespace handling, here's a one-liner that doesn't care, as long as you know the direct path:

    ([xml](Get-Content -Path "path\to.xml")).Peoples.Person.Name
    

    The above will return all matching nodes as well. It's not as powerful, but it's clean when you know the schema and want one thing out of it quickly.

提交回复
热议问题