$xml = [xml] @'
<?xml version="1.0" encoding="UTF-8"?>
<group>
<product description="phone" id="1234/5678">
<item name="apple" version="50" />
<item name="banana" version="100" />
</product>
<product description="notebook" id="6666/7777">
<item name="orange" version="150" />
</product>
</group>
'@
$xml.group.product[0].item[0].name
works (returns 'apple'
), because the 1st product
element has 2 item
child elements.
However, $xml.group.product[1].item[0].name
does not work (returns $null
), because there is only one item
element.
How can I reliably access the first item
child element without having to know whether it happens to be the only one?