I have an XML File with the following format:
<containers>
<container>
<item>
item name
</item>
<item>
item name
</item>
<item>
item name
</item>
</container>
<container>
<item>
item name
</item>
</container>
</containers>
I need to use javascript to get the first item name in the second container. I was going to use xmldoc.getElementsByTagName("item")[3].childNodes[0].nodeValue; but I have no way of knowing how many items will be in the first container, so I’m looking for a way to select the second container then the item’s name.
First, select the container tags. If you have 2 or more container tags, take the first child node of the second container. Something like this (may not be exact, haven’t tested it):