1

我正在尝试将未知数量的 HTML 文件连接到一个 XML 文件中。这没问题:

<concat destfile="${temp.dir}/file.xml" encoding="UTF-8" outputencoding="UTF-8">
    <fileset dir="${html.dir}" includes="**/*.html" />
</concat>

现在我想做的是,对于 的每个文件fileset,将其路径插入到连接文件中。

例子

我有以下 HTML 文件C:\whatever\sources

  • 一个.html
  • B.html

在结果 XML 文件中,我想得到:

  <allfiles>
   <html url="C:\whatever\sources\A.html>...content of A.html...</html>
   <html url="C:\whatever\sources\B.html>...content of B.html...</html>
  </allfiles>

有没有办法在不重新发明轮子的情况下简单地做到这一点,如果可能的话不使用ant-contrib

4

1 回答 1

0

如前所述,您可以使用内部任务在 Ant 构建中运行 Javascript scriptfilterfilterchain

例如:

<concat destfile="${temp.dir}/file.xml" encoding="UTF-8" outputencoding="UTF-8">
    <fileset dir="${html.dir}" includes="**/*.html" id="my-files"/>
    <filterchain>
        <tokenfilter>
            <filetokenizer />
                 <scriptfilter language="javascript" byline="false"><![CDATA[
                     content = self.getToken();
                     // Modify content of token.
                     //content=content.replaceAll("(?s)/\\*.*?\\*/","");
                     self.setToken(content);
            ]]></scriptfilter>
        </tokenfilter>
        <striplinecomments>
            <comment value="//"/>
        </striplinecomments>
        <striplinebreaks/>
    </filterchain>
</concat>

在以下位置查找更多示例:

于 2018-01-23T23:22:05.260 回答