package fr.insee.rmes.utils;

public class XmlUtils {
	
	public static String encodeXml(String s) {
		 return s.replaceAll("&lt;&lt;([a-zA-Z]+)&gt;&gt;", "&lt;&lt; $1 &gt;&gt;") //<<texte>> => << texte >>
				 .replaceAll("&lt;([a-zA-Z]+)&gt;", "<$1>") //xml open tag
		 		 .replaceAll("&lt;([a-zA-Z]+) ([a-zA-Z:]+)?=(&quot;|')(\\S*?)(&quot;|')&gt;", "<$1 $2=\"$4\">") //open tag with one attribute (text or xml:lang)
		 		 .replaceAll("&lt;([a-zA-Z]+) ([a-zA-Z:]+)?=(&quot;|')(\\S*?)(&quot;|') ([a-zA-Z:]+)?=(&quot;|')(\\S*?)(&quot;|')&gt;", "<$1 $2=\"$4\" $6=\"$8\">") //open tag with 2 attributes (text or xml:lang)
		 		 .replaceAll("&lt;([a-zA-Z]+) ([a-zA-Z:]+)?=(&quot;|')(\\S*?)(&quot;|') ([a-zA-Z:]+)?=(&quot;|')(\\S*?)(&quot;|') ([a-zA-Z:]+)?=(&quot;|')(\\S*?)(&quot;|')&gt;", "<$1 $2=\"$4\" $6=\"$8\" $10=\"$12\">") //open tag with 3 attributes (text or xml:lang)
		 		 .replaceAll("&lt;([a-zA-Z]+) ([a-zA-Z:]+)?=(&quot;|')(\\S*?)(&quot;|') ([a-zA-Z:]+)?=(&quot;|')(\\S*?)(&quot;|') ([a-zA-Z:]+)?=(&quot;|')(\\S*?)(&quot;|') ([a-zA-Z:]+)?=(&quot;|')(\\S*?)(&quot;|')&gt;", "<$1 $2=\"$4\" $6=\"$8\" $10=\"$12\" $14=\"$16\">") //open tag with 4 attributes (text or xml:lang)
				 .replaceAll("&lt;/([a-zA-Z]+)&gt;", "</$1>") //xml close tag
				 .replaceAll("&lt;([a-zA-Z]+)/&gt;", "<$1/>") //br
				 .replaceAll("&lt;([a-zA-Z]+) /&gt;", "<$1 />") //br with space

	 			; 



	}

}

@@ -313,35 +313,36 @@
 %5D+)?=(&quot;%7C')(
-%5C%5CS
+%5B%5E=%5D
 *?)(&quot;%7C')&gt
@@ -464,35 +464,36 @@
 %5D+)?=(&quot;%7C')(
-%5C%5CS
+%5B%5E=%5D
 *?)(&quot;%7C') (%5B
@@ -507,35 +507,36 @@
 %5D+)?=(&quot;%7C')(
-%5C%5CS
+%5B%5E=%5D
 *?)(&quot;%7C')&gt
@@ -667,35 +667,36 @@
 %5D+)?=(&quot;%7C')(
-%5C%5CS
+%5B%5E=%5D
 *?)(&quot;%7C') (%5B
@@ -710,35 +710,36 @@
 %5D+)?=(&quot;%7C')(
-%5C%5CS
+%5B%5E=%5D
 *?)(&quot;%7C') (%5B
@@ -753,35 +753,36 @@
 %5D+)?=(&quot;%7C')(
-%5C%5CS
+%5B%5E=%5D
 *?)(&quot;%7C')&gt
@@ -925,35 +925,36 @@
 %5D+)?=(&quot;%7C')(
-%5C%5CS
+%5B%5E=%5D
 *?)(&quot;%7C') (%5B
@@ -968,35 +968,36 @@
 %5D+)?=(&quot;%7C')(
-%5C%5CS
+%5B%5E=%5D
 *?)(&quot;%7C') (%5B
@@ -1011,35 +1011,36 @@
 %5D+)?=(&quot;%7C')(
-%5C%5CS
+%5B%5E=%5D
 *?)(&quot;%7C') (%5B
@@ -1066,11 +1066,12 @@
 %7C')(
-%5C%5CS
+%5B%5E=%5D
 *?)(

fix issue with space in style attribute (and ignore two much attribute)