How to get all node attributes in a specific javascript xml namespace

I have a node from an XML document. It has several attributes on several namespaces. I want to find all the attributes from the fo namespace. How can this be done? for example, from the following I would like to get all the attributes starting with fo:

<thingy fo:line-height="200%" fo:blah="blah" gh:sdf="sdfdfer"> blah </thingy> 
+4
source share
1 answer
 var tag = document.getElementsByTagName('thingy')[0]; var attr = tag.attributes; for(var i=0;i<attr.length;i++) { if(attr.item(i).nodeName.search('fo:') == 0) { alert(attr.item(i).nodeName); alert(attr.item(i).nodeValue); } } 

Working js script

+4
source

All Articles