为什么没有用此代码打印出来:
$xml=[xml]@'
<?xml version="1.0" encoding="iso-8859-1"?>
<catalogue>
<products>
<product id="pdt1">
<metas>
</metas>
</product>
<product id="pdt2">
<metas date="2015.07.24">
<meta code="123456" value="abcdef" />
<meta code="789012" value="ghijkl" />
<meta code="345678" value="mnopqr" />
</metas>
</product>
</products>
</catalogue>
'@
$product_id = "pdt2"
$metas = $xml.SelectSingleNode("//catalogue/products/product[@id='$product_id']/metas")
Foreach ($meta in $metas) {
Write-Host $meta.code
Write-Host $meta.value
}
答案 0 :(得分:4)
改变这个:
Foreach ($meta in $metas) {
到此:
Foreach ($meta in $metas.meta) {