I have the following XML in a ‘loader’ through Ajax call:
<Room Category>
<PriceRanges>
<PriceRange>
<DateRange>
<FromDate>2011-06-10</FromDate>
<ToDate>2011-06-15</ToDate>
</DateRange>
<Price Gross='44.00' Nights='5' />
</PriceRange>
<PriceRange>
<DateRange>
<FromDate>2011-06-16</FromDate>
<ToDate>2011-06-25</ToDate>
</DateRange>
<PriceInfo>Some price info</PriceInfo>
<Price Gross='40.00' Nights='10' />
</PriceRange>
</PriceRanges>
</RoomCategory>
Note that there can be an unknown number of PriceRange nodes.
I also have the following code:
priceranges = loader.doXml('//RoomCategory/PriceRanges/PriceRange')
I want to iterate over each PriceRange and get the Gross Attribute for each Price node. Note that the Price node within the PriceRange is sometimes at childNode[1] and sometime at childNode[2] depending on whether the PriceInfo node exists. I have tried the following but that does not work.
for(pr=0; pr<priceranges.length; pr++)
{
price = priceranges[pr].childNode['Price'].getAttribute('Gross')
}
However that does not work. Firebug says:
priceranges[pr].childNode.Price is undefined.
Please can you tell me how to get to the Price node from priceranges[pr].
Thanks
Purvez