title: Edit a XML file from bash shell
body: <p>Want to edit XML file thru bash shell script.
  I am stuck in finding a solution - Kindly share your suggestion if this can be resolved via bash shell script.</p>
  
  <p>Input File(Will be stored in server):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;properties&gt;
   &lt;directories installDir="/fs0/"&gt;
    &lt;directoriesInstance id="sharedDir" path=""/&gt;
    &lt;directoriesInstance id="loaderInput" path="/fs0/share/iad/input"/&gt;
    &lt;directoriesInstance id="loaderProcessing" path="/fs0/share/iad/processing"/&gt;
    &lt;directoriesInstance id="loaderError" path="/fs0/share/iad/error"/&gt;
    &lt;directoriesInstance id="loaderCompleted" path="/fs0/share/iad/completed"/&gt;
   &lt;/directories&gt;
    
    &lt;applicationServerInstance id="app" serviceName="App Server" rmiPort="15001" jvmParameters="-Xmx3072m -Xms512m -XX:-UseGCOverheadLimit -XX:MaxPermSize=196m -Dsun.lang.ClassLoader.allowArraySyntax=true -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/fs0/clarity1/clarity/logs -Xloggc:/fs0/clarity1/clarity/logs/app_gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -Dcustom.properties=/fs0/share/custom.properties" maxThreads="1000" programParameters="" distributed="false" runJobScheduler="false" useSSO="true" maxConcurrentJobs="10" runProcessEngine="false" messageTimeToLive="120" messageReceiverInterval="5" exceptionRunInterval="normal" maxXmlNodesLimit="150000"/&gt;
    &lt;applicationServer&gt;
    &lt;applicationServerInstance id="app" serviceName=" App Server" rmiPort="15001" jvmParameters="-Xmx3072m -Xms512m -XX:-UseGCOverheadLimit -XX:MaxPermSize=196m -Dsun.lang.ClassLoader.allowArraySyntax=true -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/fs0/clarity1/clarity/logs -Xloggc:/fs0/clarity1/clarity/logs/app_gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -Dcustom.properties=/fs0/clarity1/share/custom.properties" maxThreads="1000" programParameters="" distributed="false" runJobScheduler="false" useSSO="true" maxConcurrentJobs="10" runProcessEngine="false" messageTimeToLive="120" messageReceiverInterval="5" exceptionRunInterval="normal" maxXmlNodesLimit="150000"/&gt;
   &lt;/applicationServer&gt;
  
  &lt;/properties&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>In the above snippet I wanted to search for applicationServerInstance Tag and look if it has Dcustom.properties=/fs0/clarity1/share/custom.properties in jvmproperties tag - if it does not exists i wanted to add to the file and save the file.
  All should be in bash shell script.</p>
  
  <p>I want to add <strong>-Dcustom.properties=/fs0/share/custom.properties</strong> value to <strong>jvmParameters</strong> attribute In <strong>applicationServerInstance</strong> tag if it does not exists. In the above example it has this value,but incase if it does not exists I wanted to add this  <strong>-Dcustom.properties=/fs0/share/custom.properties</strong> value.</p>
  
  <p>Say for Example I should add the <strong>-Dcustom.properties=/fs0/share/custom.properties</strong> value to <strong>jvmParameters</strong> attribute In <strong>applicationServerInstance</strong> tag to the below snippet.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;applicationServerInstance id="app" serviceName=" App Server" rmiPort="15001" jvmParameters="-Xmx3072m -Xms512m -XX:-UseGCOverheadLimit -XX:MaxPermSize=196m -Dsun.lang.ClassLoader.allowArraySyntax=true -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/fs0/clarity1/clarity/logs -Xloggc:/fs0/clarity1/clarity/logs/app_gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC " maxThreads="1000" programParameters="" distributed="false" runJobScheduler="false" useSSO="true" maxConcurrentJobs="10" runProcessEngine="false" messageTimeToLive="120" messageReceiverInterval="5" exceptionRunInterval="normal" maxXmlNodesLimit="150000"/&gt;</code></pre>
  </div>
  </div>
  </p>