i have always struggles getting xml in javascript to work consistently across browsers. i usually have stuck to traversing a little more manually than using the getelementsbytagname method:
<response> <methodcall>update</methodcall> <result> <status></status> <message></message> </result> </response> var fields = e.responseXML.documentElement.childNodes; var method = fields[0].firstChild.nodeValue; var result = fields[1].firstChild.nodeValue; var status = result.childNodes[0].firstChild.nodeValue; var message = result.childNodes[1].firstChild.nodeValue; // or a for loop: for (var i = 0, total = fields.length; i < total; i++) { var field = fields[i]; if (field.nodeName == 'result') { var fieldNodes = field.childNodes; var status = fieldNodes[0].firstChild.nodeValue; var message = fieldNodes[1].firstChild.nodeValue; } } On Sep 8, 6:25 am, Phil Petree <phil.pet...@gmail.com> wrote: > Essentially, you have to reference the XML data in node order, if you try to > reference the first node AFTER you have referenced all the other nodes, the > first node gets returned as empty. > > Take an XML data set defined as: > <data> > <status>OK</status> > <record>22</record> > <userid>bart</userid> > <date>09/01/2010</date> > . > . > . > </data> > > ========== THIS WORKS ON THE FIRST DATA NODE ============ > // Now, in the javascript on the form do this (and this works fine): > $('ajStatus').value = > transport.responseXML.getElementsByTagName('status')[0].firstChild.nodeValu e; > > $('ajRecord').value = > transport.responseXML.getElementsByTagName('record')[0].firstChild.nodeValu e; > > $('ajUserid').value = > transport.responseXML.getElementsByTagName('userid')[0].firstChild.nodeValu e; > > $('ajDate').value = > transport.responseXML.getElementsByTagName('date')[0].firstChild.nodeValue; > > ========== THIS FAILS ON THE FIRST DATA NODE ============ > // Turn it around and do this (and the last value will NEVER get set): > $('ajRecord').value = > transport.responseXML.getElementsByTagName('record')[0].firstChild.nodeValu e; > > $('ajUserid').value = > transport.responseXML.getElementsByTagName('userid')[0].firstChild.nodeValu e; > > $('ajDate').value = > transport.responseXML.getElementsByTagName('date')[0].firstChild.nodeValue; > > // this will fail!!! > $('ajStatus').value = > transport.responseXML.getElementsByTagName('status')[0].firstChild.nodeValu e; -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.