3

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

  • Is an XML namespace already "imported" into the document (with xmlns:blah="http://...) - knowing the http://... part.
  • What moniker (in the above example blah) used.

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?

1 Answer 1

4

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://...')

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

2 Comments

My problem is to find namesapces already imported (so I can import it if it is not already in the document). I have no knowledge about any tag names. - In other words I ofc. know the name of the tag I would like to insert but nothing guarantees that some other tag is not already used from the namesapce and thus the namesapce already imported.
Oh, right. I read the question wrong. Have you tried doc.lookupPrefix('http://...')?

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.