Getting XML Element by name in ajax responseXML?
I'm having an issue with an AJAX script I'm fixing - an AJAX connection is being made, XML data is returned (Properly), however the data is not being shown correctly in any browser other than IE. Elements are being gotten by using xmlData.childNodes[1] - which works fine in IE, but in Opera, Firefox, Chrome, etc., different data is returned than what is returned in IE.开发者_如何学Python I think IE uses a different method of indexing DOM elements, so rather than starting at 0 it starts at 1, or something along those lines.
Anyways, knowing that - how can I get data from an XML element by referencing the name of the element? If that's not possible, how can I get around this indexing issue?Are you getting anything back in those other browsers? Maybe the xml is coming back with the wrong mime type?
Your probably better off using the selector methods rather than just childNodes. ie
elements = xmldoc.getElementByTagName('tag')
element = xmldoc.getElementById('id')
This way if the xml changes in the future you won't have to remember about which index pointed where.
Have you taken a look at: http://www.w3schools.com/dom/dom_nodes_access.asp
As well as the examples here: http://www.w3schools.com/dom/dom_nodes_info.asp
精彩评论