Good day.

I wrote a script that accesses a third-party service, sending xml and receiving another xml in response.

After that I need to pull out the values ​​of some tags from the received xml.

I do it like this:

var result = response.getElementsByTagName('serv:result')[0].innerHTML 

The problem is that some browsers do not search for tags that have a colon inside; you just need to write "result" instead of "serv: result" for them. Other browsers, on the contrary, search for only the full name with a colon.

I already nagulit that the colon in a tag belongs to such concept as "xml name spaces". But according to these words, Google gives out huge amounts of general information, and I need to solve only one specific issue.

Is there a way for JS to search normally for xml tags with a colon?

  • one
    Different browsers and true xml are treated differently. I would translate xml into text, and use regex and split to get the necessary information. (I did it more than once) - nick_n_a
  • one
    The second way, you can write like this (response.getElementsByTagName('serv:result') | response.getElementsByTagName('serv') )[0].innerHTML not found in the 1st way - let it search for the second. - nick_n_a

1 answer 1

Everything googled.

There is a special function getElementsByTagNameNS (). It works like this:

 response.getElementsByTagNameNS(NamespaceURI, "result")[0].childNodes[0].nodeValue 

The values ​​of NamespaceURI are written at the beginning of the very response xml.