qshinoの日記

Powershell関係と徒然なこと

powershell xml 要素取り出し

powershellxml要素取り出し

 

基本は doc に対して

-> firstchild

-> childnodes

-> foreach

-> $_.name と$_.innertext

 

例)

mono.xml の内容

<top>

  <iro>ao</iro>

  <omosa>10</omosa>

</top>

powershell

 

$doc = [xml](get-content "mono.xml")

$root = $doc.firstchild

$children = $root.ChildNodes()

$children | foreach { write-host $_.name $_.innertext }

 

出力が

iro ao

omosa 10

 

こんな感じ