且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用JavaScript删除XML命名空间的简单方法?

更新时间:2023-11-28 21:07:16

如果代码中没有< script> 可以尝试演示

  container.innerHTML = container.innerHTML 
.replace(/<(\ /?)([^:> \s] *: )?([^>] +)> / g,< $ 1 $ 3>)


Is there an easy way, for example, to drop an XML name space, but keep the tag as is with jQuery or JavaScript? For example:

<html:a href="#an-example" title="Go to the example">Just an Example</html:a>

And change it to:

<a href="#an-example" title="Go to the example">Just an Example</a>

On the fly with jQuery or JavaScript and not knowing the elements and or attributes inside?

If there is no <script> tag in the code to be replaced you can try (demo):

container.innerHTML = container.innerHTML
                               .replace(/<(\/?)([^:>\s]*:)?([^>]+)>/g, "<$1$3>")