Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ant从xml文件中删除行_Ant - Fatal编程技术网

ant从xml文件中删除行

ant从xml文件中删除行,ant,Ant,我想用ant脚本删除所有的doctype <?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" > 我仅成功删除我尝试了此解决方案: replac

我想用ant脚本删除所有的doctype

<?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" >


我仅成功删除
我尝试了此解决方案:

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>

使用正则表达式操作xml文档非常容易出错。使用XML文档并进行更改。试试groovy:
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>
<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>