java - Regex to remove the uri prefix (within tag) only from xml tag -
i need regular expression remove uri prefix(within tag) xml tag.
example
input:
<ns1:fso xlmns:="http://xyz"><sender>abc</sender></ns1:fso>
output:
<fso xlmns:="http://xyz"><sender>abc</sender></fso>
here 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); // matcher object stringbuffer sb = new stringbuffer(); while (m.find()) { m.appendreplacement(sb, replace); } m.appendtail(sb); system.out.println(sb.tostring()); }
i not able paste input xml here
private static string input =
is not correct 1 shown in above code. instead can take example of soap message.
i more used perls regex engine, if works same, it:
private static string regex1 = "(<\\/?)[a-z0-9]+:";
and
private static string replace = "$1";
Comments
Post a Comment