我已经阅读Xml文件使用下面给出的代码 –
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();
现在我得到以下格式的XmlString sting:
<?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>
我想删除<?xml version =“1.0”encoding =“UTF-8”standalone =“no”?>从上面的字符串.所以我有写代码
XmlString=XmlString.replaceAll("<?xml*?>","").trim();
但是仍然XmlString是一样的.所以请帮我从XmlString中删除版本信息.
解决方法
将正则表达式更改为
XmlString=XmlString.replaceAll("\\<\\?xml(.+?)\\?\\>","").trim();