Adjusting XML config files from a script

I'm working on automating the configuration of several JBoss servers, which involves editing a substantial number of XML files.

I'd like to script all these changes as much as possible. But the "standard" tools (sed, grep et al) do not work well with XML. Without necessarily resorting to a higher-level language, how can I script e.g. the insertion of a given XML snipper after a given XML element in a certain file?

Say for instance 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. What's the easiest way to do that from a script?

Answers


You'll find more answers in my previous question. xmlstar seems to be the most popular answer.


Need Your Help

problems geting values from xml

php xml simplexml feeds

Im trying to get some values from the below xml feed

Scraping/Parse URL for Images

html ios objective-c parsing swift

So I would like to Scrap a URL to get all IMG-Tags from the HTML in iOS.