In the following code excerpt, products is a xml nodelist, which structure is:
<products>
<product>
<id>1</id>
<name>item1</name>
</product>
<product>
<id>2</id>
<name>item2</name>
</product>
</products>
xml = httpRequest.responseXML
products = xml.getElementsByTagName('products')
products[0].constructor
//=>ElementConstructor
product = products[0]
//=><product>…</product>
product.constructor
//=>ElementConstructor
product.getElementsByTagName('id')
//[ <id>1</id> ]
for(product in products){product.getElementsByTagName('id')}
//=>TypeError: 'undefined' is not a function (evaluating 'product.getElementsByTagName('id')')
how can I iterate each <product> element in <products> element, and select only tag
for(product in products):This code:
Gives:
If you want to loop over the elements, then you need to use a regular
forloop.