【问题标题】:Ant Macro use element's content as the value of an attributeAnt Macro 使用元素的内容作为属性的值
【发布时间】:2012-02-28 10:38:22
【问题描述】:

我想使用名为“soql”的元素的内容作为替换过滤器中的属性。我想要实现的是用元素的内容替换文件中的值。在这种情况下,我倾向于不使用属性,因为值应该包含在 CDATA 块中

 <macrodef name="exportdata">
            <attribute name="file"/>
            <attribute name="object"/>
            <element name="soql"/>
            <sequential>
                <echo message="Exporting @{object}"/>
                <mkdir dir="data/exports"/>

                <copy file="data/config/template-process-conf.xml" tofile="data/config/process-conf.xml" overwrite="true" failonerror="true"/>

                            <replace file="data/config/process-conf.xml">
                            <replacefilter token="_endpoint_" value="${sf.serverurl}"/>

                    <replacefilter token="_username_" value="${sf.username}"/>
                    <replacefilter token="_password_" value="${encryptedpassword}"/>
                            <replacefilter token="_object_" value="@{object}"/>
                            <replacefilter token="_soql_" value="@{soql}"/>
                            <replacefilter token="_file_" value="data/exports/@{file}.csv"/>
                    <replacefilter token="_keyfile_" value="data/config/key.txt"/>
                        </replace>

                <java classname="com.salesforce.dataloader.process.ProcessRunner" classpath="lib/DataLoader.jar" failonerror="true">
                    <sysproperty key="salesforce.config.dir" value="data/config"/>
                    <arg line="process.name=export@{object}"/>
                </java>
            </sequential>
        </macrodef>

【问题讨论】:

    标签: ant macros attributes replace element


    【解决方案1】:

    如果您有相当最新的 Ant (>1.7) 版本,您可以使用 string 资源来执行此操作。这是一个简单的例子:

    <macrodef name="element2string">
      <element name="elem"/>
      <sequential>
          <string id="elem.as.string"><elem/></string>
          <echo message="${toString:elem.as.string}"/>
      </sequential>
    </macrodef>
    
    <element2string>
        <elem><![CDATA[There be <dragons>]]></elem>
    </element2string>
    

    结果:

    [echo] There be <dragons>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-25
      • 1970-01-01
      • 1970-01-01
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多