I'm trying to manually add some prefixes to my xml string, for this I need a particular java expression that I just can't seem to find, basically this my string:
<?xml version="1.0" encoding="UTF-8"?>
<mediabericht xmlns:mb="http://www.mediabericht.org"><inhoud>Randominhoud 22</inhoud><netwerk>Twitter</netwerk><datum>1408625886036</datum><film>Gladiator</film></mediabericht>
I want to add prefixes to my elements, so it should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<mb:mediabericht xmlns:mb="http://www.mediabericht.org"><mb:inhoud>Randominhoud 22</mb:inhoud><mb:netwerk>Twitter</mb:netwerk><mb:datum>1408625886036</mb:datum><mb:film>Gladiator</mb:film></mb:mediabericht>
I want to do a few replaceall's but so far I had no luck
The first regex I need to solve is < but not <? or </
and use the replaceAll function to replace these by <mb:
(the prefix)
Then the second replacement I've handled:
String prefixedString = xmlString.replaceAll("</", "</mb:");