Ant xmlproperty task. What happens when there is more than one tag with the same name?

前端 未结 1 825
情歌与酒
情歌与酒 2021-01-12 08:09

I am trying to follow a large ant buildfile that I have been given, and I am having trouble understanding the functionality of xmlproperty in this case. Consider this xml fi

相关标签:
1条回答
  • 2021-01-12 08:48

    When multiple elements have the same name, <xmlproperty> creates a property with comma-separated values:

    <project name="ant-xmlproperty-with-multiple-matching-elements" default="run" basedir=".">
        <target name="run">
            <xmlproperty file="example.xml" prefix="PREFIX" />
    
            <echo>${PREFIX.main.tagList.tag.file}</echo>
        </target>
    </project>
    

    The result:

    run:
         [echo] file1,file2
    

    To process the comma-separated values, consider using the <for> task from the third-party Ant-Contrib library:

    <project 
        name="ant-xmlproperty-with-multiple-matching-elements" 
        default="run" 
        basedir="." 
        xmlns:ac="antlib:net.sf.antcontrib"
        >
        <taskdef resource="net/sf/antcontrib/antlib.xml" />
        <target name="run">
            <xmlproperty file="example.xml" prefix="PREFIX" />
    
            <ac:for list="${PREFIX.main.tagList.tag.file}" param="file">
                <sequential>
                    <echo>@{file}</echo>
                </sequential>
            </ac:for>
        </target>
    </project>
    

    The result:

    run:
         [echo] file1
         [echo] file2
    
    0 讨论(0)
提交回复
热议问题