Concatenate xml file in ant script

后端 未结 2 412
面向向阳花
面向向阳花 2021-01-25 12:49

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

相关标签:
2条回答
  • 2021-01-25 13:16

    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="&lt;\?xml version"/>
            </linecontainsregexp>
        </filterchain>  
     </concat>
    
    0 讨论(0)
  • 2021-01-25 13:25

    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>
    
    0 讨论(0)
提交回复
热议问题