0

Why nothing prints out with this code :

$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

}

1 Answer 1

4

Change this:

Foreach ($meta in $metas) {

to this:

Foreach ($meta in $metas.meta) {
Sign up to request clarification or add additional context in comments.

2 Comments

Beat me to it. My solution was use $xml.SelectNodes("//catalogue/products/product[@id='$product_id']/metas/meta").
Post that. It's enough different, and it's worth having both options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.