How do I remove namespaces from xml in java?

4.05K viewsJavaSpring
0

How do I remove namespaces from xml in java?

Manohar Changed status to publish June 19, 2019
Add a Comment
2
public static String removeXmlNamespaceAndPreamble(String xmlString) {
		  return xmlString.replaceAll("(<\\?[^<]*\\?>)?", ""). 
		  replaceAll("xmlns.*?(\"|\').*?(\"|\')", "") 
		  .replaceAll("(</)(\\w+:)(.*?>)", "$1$3") 
		  .replaceAll(":","");
		  .replaceAll("(<)(\\w+:)(.*?>)", "$1$3")
		 		 
}

I hope the above snippet will work, please try.

Manohar Changed status to publish June 19, 2019
Add a Comment
Write your answer.