ant从xml文件中删除行

时间:2013-03-28 16:06:13

标签: ant

<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

...

我想删除使用ant脚本,所有doctype

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

我成功删除<!DOCTYPE使用:

&LT;

replaceregexp >
      <regexp pattern="&lt;DOCTYPE hibernate-mapping PUBLIC
        &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot;
        &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot; &gt;"/>
      <substitution expression=""/>
      <fileset  file="${subproject.build.pre-dist.dir}/WEB-INF/struts-config.xml">

      </fileset>
    </replaceregexp>

如何删除所有内容?

1 个答案:

答案 0 :(得分:0)

我尝试了这个解决方案:

<target name="test" depends ="init">
    <loadfile 
        srcfile="${subproject.build.pre-dist.dir}/WEB-INF/struts-config.xml" 
        property="src.file.head1">
    <filterchain>
        <headfilter lines="-1" skip="3"/>
    </filterchain>
    </loadfile>


    <echo  file ="${subproject.build.pre-dist.dir}/WEB-INF/struts-config.xml"
    message="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
        ${src.file.head1}"/>
</target>