How do I remove namespaces from xml in java?

2.41K viewsJavaSpring
0

How do I remove namespaces from xml in java?

Changed status to publish
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.

Changed status to publish
Add a Comment
You are viewing 1 out of 1 answers, click here to view all answers.
Write your answer.