Hi. Internet Explorer has support for xml response parsing and lets you do
element.xml.attributes.getNamedItem('myAttr')
How can I do the same for an xml element in standards based browsers?
The type of element is [object Element]
Hi. Internet Explorer has support for xml response parsing and lets you do
element.xml.attributes.getNamedItem('myAttr')
How can I do the same for an xml element in standards based browsers?
The type of element is [object Element]
Use the standard DOM instead of Microsoft's propriety approach. (Assuming you are talking about a proper XML document and not an IE4 era "XML data island")
OK, derived the answer using FireBug from here: Versatile xml attribute regex with javascript
element.ownerDocument.evaluate("//@"+attributeName, element.ownerDocument, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null).iterateNext().nodeValue;
function GetAttributeValueFromXmlElement(element, attrName) {
if (element && element.xml) {
//msie
return $(element.xml)[0].attributes.getNamedItem(attrName).value;
} else {
//standard DOM
if (true/*Should check if there's only one here and only where expected to be*/) {
return element.ownerDocument
.evaluate("//@" + attrName, element.ownerDocument, null
, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null)
.iterateNext().nodeValue;
}
}
}