Hi I am trying to access a node’s elements with childNodes. Here is a sample XML
<ROOT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<node>
<nodeid>28</nodeid>
<account_no xsi:nil="true" />
<address1>15 CANCUN CT</address1>
<serial_no>112199543</serial_no>
<x_lat>25.95513358000</x_lat>
<y_lon>-97.49027147000</y_lon>
<alarm>
<alarmid>Outage</alarmid>
<alarmtime>2012-07-30T14:46:29</alarmtime>
</alarm>
<alarm>
<alarmid>Restore</alarmid>
<alarmtime>2012-07-30T14:48:37</alarmtime>
</alarm>
</node>
</ROOT>
I’m trying to get the second childNodes but can’t using javascript. I can however get the nodevalues from the first by this js code.
var alarmId = xmlDocOut.getElementsByTagName('alarmid')[i].childNodes[0].nodeValue;
var alarmTime = xmlDocOut.getElementsByTagName('alarmtime')[i].childNodes[0].nodeValue;
If i try to use …[i].childNodes[1].nodeValue the js will throw an error saying ‘Object Required’ on that line.
I’ve tried
...[i].childNodes[1...4].nodeValue
and
...[i].childNodes[0].childNodes[0].nodeValue.
And still nothing!
i got it, i just had to add an …[i+1].childNodes[0].nodeValue to the subscript to get the second alarm elements.