I created an XML document using Java in my android application. I have to call a web service in my application and pass this XML as an argument there. But my problem is ther
This is the regular expression (?:>)(\s*)<
When you use it in the code for Java use
"(?:>)(\\s*)<"
and replace with "><"
String xmlString = "<note> <to>Tove</to> <from>Jani</from <heading>Reminder</heading> <title>Today</title> <body>Don't forget me this weekend!</body> </note>";
String str = xmlString.replaceAll("(?:>)(\\s*)<", "><");
This will remove the spaces between the tags and maintain the spaces for the value.
Input:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading> <title>Today</title>
<body>Don't forget me this weekend!</body>
</note>
Output:
<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><title>Today</title><body>Don't forget me this weekend!</body></note>