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>
Please help me out in Javascript. Thanks a lot
PS : Extremely sorry if this question has been asked before. I searched quite a lot but didn't get the info.
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>
Please help me out in Javascript. Thanks a lot
PS : Extremely sorry if this question has been asked before. I searched quite a lot but didn't get the info.
Share Improve this question asked Feb 11, 2014 at 10:20 StackAddictStackAddict 4231 gold badge9 silver badges21 bronze badges 3- how you process this XML in javascript? – Piotr Stapp Commented Feb 11, 2014 at 10:25
- I receive a DOM object which has the XML. I serialize it into String format, convert it into JSON and process it. – StackAddict Commented Feb 11, 2014 at 10:38
- 1 check this stackoverflow./questions/20346243/… – Naren Commented Feb 11, 2014 at 10:38
1 Answer
Reset to default 19The following code should do the work (http://jsfiddle/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);