4

I have a node from an xml document. It has several attributes on it from multiple namespaces. I want to find all the attributes from the fo namespace. How can this be done? e.g. from the following I would want to get all of the attributes starting in fo:

<thingy fo:line-height="200%" fo:blah="blah" gh:sdf="sdfdfer">
blah
</thingy>

1 Answer 1

4
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 Fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.