1

I have a set of xml files in a directory and as part of my build process using Ant I would like to remove an entire node based on the text inside a child node. An example is like this:

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
  ...
  ...
  <fields>
    <fullName>agf__ADM_Work__c</fullName>
    <deleteConstraint>SetNull</deleteConstraint>
    <deprecated>false</deprecated>
    ...
    ...
  </fields>
  ...
  ...
</CustomObject>

In this example I want to remove all nodes completely if the text inside begins with agf__ There are many node that qualify for this in many files, and the number of child nodes under varies.

I have used 'replacedregexp' of ant before and matched the entire mode, all children in the past and this works like:

<replaceregexp match="&lt;fieldPermissions&gt;\s*&lt;editable&gt;(.+?)&lt;/editable&gt;\s*&lt;field&gt;(.*).agf__(.*)&lt;/field&gt;\s*&lt;readable&gt;(.+?)&lt;/readable&gt;\s*&lt;/fieldPermissions&gt;\s*" replace="" flags="gm" byline="false">
    <fileset dir="${basedir}/src/permissionsets" includes="*.permissionset"/>
</replaceregexp>

which will remove something like:

<fieldPermissions>
    <editable>false</editable>
    <field>something.agf__something</field>
    <readable>true</readable>
</fieldPermissions>

But i am not sure how to accomplish this when the markup of the node to be removed changes.

So then I tried using xmltask, which I managed to get to work using the exact field text like this:

<xmltask todir="${basedir}/src/objects">
        <fileset dir="${basedir}/src/objects" includes="*.object" />
        <remove path="//:CustomObject/:fields[:fullName/text()='agf__ADM_Work__c']"/>
</xmltask>

This works and remove the node in the first example on any of the files in the 'objects' directory the end in .object However I believe the remove task of the xmltask does not take wild cards or regexp's to match agf__*. The values of fullName that begin with agf__ are many and vary.

I hope I was clear enough and hope some one can assist me. Thanks

Dave Hahn
  • 11
  • 1

0 Answers0