Setting XML configuration files from script
I am working on automating the configuration of multiple JBoss servers, which involves editing a significant amount of XML files.
I would like to script to make all of these changes as much as possible. But "standard" tools (sed, grep, etc.) do not work well with XML. Not necessarily resorting to a higher level language, how can I script for example. inserting a given XML-snipper after a specific XML element in a specific file?
Say for example that my jboss-log4j.xml looks like
<!-- ====================== -->
<!-- More Appender examples -->
<!-- ====================== -->
<!-- Buffer events and log them asynchronously -->
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<appender-ref ref="FILE"/>
<!--
<appender-ref ref="CONSOLE"/>
<appender-ref ref="SMTP"/>
-->
</appender>
and that I want to add a new appender-ref element. The easiest way to do this with a script?
source to share
NAnt, the .NET cousin from Ant, has XmlPeek and XmlPoke tasks that I have used to very good effect when editing WCF config files, which are quite complex. If you can find similar tasks for Ant, you might have a winner.
Alternatively, another approach could be to have a "template" version of the config file containing% placeholders%, suitable for replacement with one of the more classic word processing tools.
Thought - Ant has an idea for a filter chain that can be used to convert a file on copy - NAnt has the same concept, and I recently used that to good effect when setting up deployment files.
source to share