title: Scala: How to append new node to an XML file and how to delete a node from an XML file
body: <p>I have just started coding in Scala and I am facing difficulties with this very basic XML structure:</p>
  
  <pre><code>&lt;Countries&gt;
  
      &lt;Country&gt;
          &lt;Name&gt;Italy&lt;/Name&gt;
          &lt;Continent&gt;Europe&lt;/Continent&gt;
      &lt;/Country&gt;
  
      &lt;Country&gt;
          &lt;Name&gt;Japan&lt;/Name&gt;
          &lt;Continent&gt;Asia&lt;/Continent&gt;
      &lt;/Country&gt;
  
  &lt;/Countries&gt;
  </code></pre>
  
  <p>Problem 1: I would like to add a new node(a new country) to the file. I successfully loaded the file using XML.loadFile but have no idea how to add the new node and then save back the file.</p>
  
  <p>Problem 2: I would also like to delete nodes from the file but even here I am finding difficulties to achieve what I want especially since I want to delete the node where the  element matches the country name inputted by the user.</p>
  
  <p>I used a piece of code I found online:</p>
  
  <pre><code>val removeIt = new RewriteRule {
      override def transform(n: Node): NodeSeq = n match {
          case e: Elem if (e \ "Name").text == "Japan" =&gt; NodeSeq.Empty
          case n =&gt; n
      }
  }
  </code></pre>
  
  <p>This works but unfortunately it returns back a NodeSeq that is not accepted as a parameter of Xml.Save and also I have no idea how to pass a String parameter to determine which node to delete.</p>