I have read Xml File using code given below-
String XmlString = \"\";
String resourcePath=FilePathHelper.getResourceFilePath(request);
BufferedRea
substring with first index of '>' + 1 ( +1 to get to next char), wont it give you end of xml version? Though it is not clean way of doing this.
Change your regular expression to
XmlString=XmlString.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim();
String xmlString = readXml();
int p1 = xmlString.indexOf("<?xml ");
int p2 = xmlString.indexOf("?>");
if ( p1 != -1 && p2 != -1 && p2>p1){
xmlString=xmlString.substring(0,p1)+xmlString(p2+2);
}
private String readXml(){
//TOTO from file or any-pipeline read,convert to String....
}
Another way would we to do it like this:
XmlString = XmlString.substring(XmlString.indexOf("<Template>"))
edit: indexOf() instead of firstIndexOf()
if(XmlString .contains("<?xml")){
XmlString = XmlString.substring(XmlString.indexOf("?>")+2);
}