删除XML中标记之间不需要的空格(Javascript) [英] Remove unwanted whitespaces between tags in XML (Javascript)
本文介绍了删除XML中标记之间不需要的空格(Javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到格式如下的XML。
I receive an XML formatted as follows.
<rec>
<id> servicedescription </id>
<name> Description Value </name>
<type> textbox </type>
</rec>
但这不起作用,因为我的系统不接受标签之间的空格。我需要以下内容
But this won't work since my system doesn't accept the spaces present between the tags. I require something as follows
<rec>
<id>servicedescription</id>
<name>Description Value</name>
<type>textbox</type>
</rec>
请帮我解决Javascript问题。非常感谢
Please help me out in Javascript. Thanks a lot
PS:非常抱歉,如果之前已经提出这个问题。我搜索了很多,但没有得到信息。
PS : Extremely sorry if this question has been asked before. I searched quite a lot but didn't get the info.
推荐答案
以下代码应该做的工作( http://jsfiddle.net/b8FBn/ ):
The following code should do the work (http://jsfiddle.net/b8FBn/):
var str = "<rec> <id> servicedescription </id> <name> Description Value </name> <type> textbox </type></rec>";
str = str.replace(/>\s*/g, '>'); // Replace "> " with ">"
str = str.replace(/\s*</g, '<'); // Replace "< " with "<"
alert(str);
这篇关于删除XML中标记之间不需要的空格(Javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文