Java – how to delete XML version strings from strings

I've read the XML file and used the 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 following format:

<?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 delete From the string above So I wrote code

XmlString=XmlString.replaceAll("<?xml*?>","").trim();

But the xmlstring is still the same So please help me delete the version information from xmlstring

Solution

Change regular expression to

XmlString=XmlString.replaceAll("\\<\\?xml(.+?)\\?\\>","").trim();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>