I am new to ant script. I am looking for how to concatenate all the xml file in a folder into a single xml file in ant script.
In my project n number of xml files will be generated dynamically in a folder eg: server1.xml, manager.xml, server2.xml, server3.xml. I need to merge all the xml files having server in their filename alone (server1.xml, server2.xml, server3.xml) into a single xml eg: server.xml. and need to deploy it in jboss.
I have found that copying content from one xml file to another using xmltask. I am not sure how to copy all the xml files content in a folder into a single xml file in ant script.
Any help is appreciated.
Well, assuming the XSLT 2.0 processor used is Saxon 9 then you can do it along the lines of e.g.
<xsl:param name="folder-uri" select="'file:/root/users/foo/foldername'"/>
<xsl:param name="select-pattern" select="'server*.xml'"/>
<xsl:variable name="docs" select="collection(concat($folder-uri, '?select=', $selectPattern))"/>
<xsl:template name="main" match="/">
<xsl:element name="{name($docs[1]/*)}" namespace="{namespace-uri($docs[1]/*)}">
<xsl:copy-of select="$docs/*/node()"/>
</xsl:element>
</xsl:template>
try this
Concatenate a series of files, update the destination file only if is older that all the source files:
Sample code:
<concat destfile="${docbook.dir}/all-sections.xml"
force="no">
<filelist dir="${docbook.dir}/sections"
files="introduction.xml,overview.xml"/>
<fileset dir="${docbook.dir}"
includes="sections/*.xml"
excludes="introduction.xml,overview.xml"/>
</concat>
avoids root tag:
<concat destfile="${docbook.dir}/all-sections.xml" force="no">
<fileset dir="${docbook.dir}" includes="sections/*.xml"/>
<filterchain>
<linecontainsregexp negate="true">
<regexp pattern="<\?xml version"/>
</linecontainsregexp>
</filterchain>
</concat>
来源:https://stackoverflow.com/questions/35695965/concatenate-xml-file-in-ant-script