vbence
vbence

Reputation: 20333

Dealing with XML namespaces in JavaScript (DOM)

I am building a tree (for SOAP) using DOM. I would like read the following info at a certain node:

Is there any way other than the manual: to walk chain of ancestors and iterate on attribute nodes, find any starting with xmlns: checking the value and if match return the rest of the attribute name?

Upvotes: 3

Views: 1873

Answers (1)

J. K.
J. K.

Reputation: 8368

Aside the usual methods such as document.getElementsByTagName, DOM offers their namespaced versions: document.getElementsByTagNameNS

Such methods take the namespace URL as their first argument.

document.getElementsByTagNameNS('http://...', 'abc');

By the way, using the regular methods, the elements might be available as…

document.getElementsByTagName('xmlns\\:abc');

This works for me in case of a HTML DOM even without "importing" any namespace.

Update:

The method OP was looking for is document.lookupPrefix('http://...')

Upvotes: 4

Related Questions