在ant脚本中连接xml文件时如何避免xml标头 [英] How to avoid xml header while concatenating xml files in ant script

查看:38
本文介绍了在ant脚本中连接xml文件时如何避免xml标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将文件夹中的所有 xml 文件连接到 ant 脚本中的单个 xml 文件中.在连接 xml 文件时,标题

I am concatenating all the xml files in a folder into a single xml file in ant script. While concatenating the xml files, the header

 <?xml version="1.0" encoding="UTF-8" ?> 

在所有 xml 文件中都附加到输出 xmlfile 中.

in all xml files are getting appended in the output xmlfile.

有没有办法避免这个标题?

Is there any way to avoid this header ?

  <concat destfile="${docbook.dir}/all-sections.xml"
      force="no">       
   <fileset dir="${docbook.dir}"
     includes="sections/*.xml"/>
   </concat>

推荐答案

您可以应用正则表达式来丢弃标题:

You can apply a regex to discard the header:

<concat destfile="${docbook.dir}/all-sections.xml" force="no">       
    <fileset dir="${docbook.dir}" includes="sections/*.xml"/>
    <filterchain>
        <linecontainsregexp negate="true">
            <regexp pattern="&lt;\?xml version"/>
        </linecontainsregexp>
    </filterchain>  
 </concat>

https://ant.apache.org/manual/Types/filterchain.html

如果你想保留标题的第一次出现,那么这是一个选项:

If you want to keep the first occurrence of the header then this is an option:

<property name="first" value="true"/>

<concat destfile="${docbook.dir}/all-sections.xml">       
    <fileset dir="${docbook.dir}" includes="sections/*.xml"/>
    <filterchain>
        <scriptfilter language="javascript">
        <![CDATA[
            first = project.getProperty("first");
            if(self.getToken().indexOf("<\?xml version") != -1) {
                if(first == "true") {
                    project.setProperty("first", "false");
                } else {
                    self.setToken(null);
                }
            }
        ]]> 
        </scriptfilter>             
    </filterchain>
</concat>

这篇关于在ant脚本中连接xml文件时如何避免xml标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆