如何从String中删除Xml版本字符串

Vir*_*mal 12 java

我使用下面给出的代码阅读了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();
Run Code Online (Sandbox Code Playgroud)

现在我以下面给出的格式得到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>
Run Code Online (Sandbox Code Playgroud)

我想<?xml version="1.0" encoding="UTF-8" standalone="no"?>从上面删除字符串.所以我写了代码为

XmlString=XmlString.replaceAll("<?xml*?>", "").trim();
Run Code Online (Sandbox Code Playgroud)

但是XmlString仍然是一样的.所以请帮我从XmlString中删除版本信息.

Ach*_*ome 30

将正则表达式更改为

XmlString=XmlString.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim();
Run Code Online (Sandbox Code Playgroud)