How do I remove namespaces from xml in java?

3.71K 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
You are viewing 1 out of 1 answers, click here to view all answers.
Write your answer.