I have an xml file where I need to comment out a whole piece of text with Ant.
There's this Ant task
<replace file="${src.dir}/Version.as"
token="@revisionPrana" value="${revision}"/>
that I use to replace words, but in my case I need to replace a whole block like this:
<value>
<object class="edumatic.backoffice.view.modules.NavigationModuleInfo">
<property name="url"
value="edumatic/backoffice/view/modules/support/ExamsNavigationModule.swf"/>
<property name="icon"
value="edumatic/backoffice/view/modules/support/assets/book.png" />
<property name="title" value="Assessments" />
<property name="pluginID" value="EXAM" />
</object>
</value>
<value>
<object class="edumatic.backoffice.view.modules.ContentModuleInfo">
<property name="url"
value="edumatic/backoffice/view/modules/support/ExamsContentModule.swf" />
<property name="pluginID" value="EXAM" />
</object>
</value>
Into
<!--value>
<object class="edumatic.backoffice.view.modules.NavigationModuleInfo">
<property name="url"
value="edumatic/backoffice/view/modules/support/ExamsNavigationModule.swf"/>
<property name="icon"
value="edumatic/backoffice/view/modules/support/assets/book.png" />
<property name="title" value="Assessments" />
<property name="pluginID" value="EXAM" />
</object>
</value>
<value>
<object class="edumatic.backoffice.view.modules.ContentModuleInfo">
<property name="url"
value="edumatic/backoffice/view/modules/support/ExamsContentModule.swf" />
<property name="pluginID" value="EXAM" />
</object>
</value-->
So, basically I need to comment out a whole block of XML. Can I do this with a replace task (putting the whole block in the attribute token and value doesn't really work)? Or is there a quick way to read in the xml with ant and delete some nodes and save the xml again?
Searching for and replace it by isn't an option because there are multiple value children and not all of them need to be commented out.
Adding a attribute like isn't an option either because the xml is being parsed by an IOC container (Prana). Maybe prana will ignore the id="1" but it still iss messy, and I don't like messy on the long term.
If you can identify what is to be replaced through a regular expression, I recommend using the optional task replaceregexp. Here's the doc: http://ant.apache.org/manual/Tasks/replaceregexp.html You can call it twice, one for the start tag and other for the end tag.
The regexp for replacing your can be a bit cumbersome, since you say you do not want to replace all tags, but I think this is the easiest way.
Another option would be to create a custom ant task to do what you want.
If it is an XML file, then you could also call an XSLT transform
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With