I need a regular expression to remove the uri prefix(within tag) only from xml tag.
Example
input:
<ns1:fso xlmns:="http://xyz"><sender>abc</sender></ns1:fso>
output:
<fso xlmns:="http://xyz"><sender>abc</sender></fso>
Here is my code:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class RegularExpressionTest {
private static String REGEX1 = "<\\/?([a-z0-9]+?:).*?>";
private static String INPUT = "<ns1:fso xmlns:ns1='https://www.example.com/fsoCanonical'>
<ns2:senderId xmlns='http://www.example.com/fsoCanonical'>abc</ns2:senderId>
<receiverId xmlns='http://www.example.com/fsoCanonical'>testdata</receiverId>
<messageId xmlns='http://www.example.com/fsoCanonical'>4CF4DC05126A0077E10080000A66C871</messageId>
</ns1:fso> ";
private static String REPLACE = "";
public static void main(String[] args) {
Pattern p = Pattern.compile(REGEX1);
Matcher m = p.matcher(INPUT); // get a matcher object
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, REPLACE);
}
m.appendTail(sb);
System.out.println(sb.toString());
}
I am not able to paste the input XML here
private static String INPUT =
is not the correct one as shown in above code. Instead you can take any example of soap message.
I am more used with PERLs RegEx engine, but if it works the same, this could be it:
and