I have read Xml File using code given below-
String XmlString = "";
String resourcePath=FilePathHelper.getResourceFilePath(request);
BufferedReader br = new BufferedReader(new FileReader(new File(resourcePath+ "SubIndicatorTemplate.xml")));
String line;
StringBuilder sb = new StringBuilder();
while((line=br.readLine())!= null){
sb.append(line.trim());
}
XmlString=sb.toString();
Now i get XmlString sting in the format given below-
<?xml version="1.0" encoding="UTF-8" standalone="no"?><Template><Caption Name="Book Details"/><Data Type="one"/><Titles><Title Name="Book no" Type="Numeric"/><Title Name="Book name" Type="Text"/></Titles></Template>
I want to remove <?xml version="1.0" encoding="UTF-8" standalone="no"?>
from above string.So i have written code as
XmlString=XmlString.replaceAll("<?xml*?>", "").trim();
But still XmlString are same. So please help me to remove version information from XmlString.
Change your regular expression to
Another way would we to do it like this:
edit: indexOf() instead of firstIndexOf()
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.