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.
XML Naming Rules Element names cannot start with the letters xml (or XML, or Xml, etc) Element names can contain letters, digits, hyphens, underscores, and periods. Element names cannot contain spaces.
Put   in string. xml file to indicate a single space in an android project.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With