title: How to change attribute on Scala XML Element
body: <p>I have an XML file that I would like to map some attributes of in with a script.  For example:</p>
  
  <pre><code>&lt;a&gt;
    &lt;b attr1 = "100" attr2 = "50"/&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>might have attributes scaled by a factor of two:</p>
  
  <pre><code>&lt;a&gt;
    &lt;b attr1 = "200" attr2 = "100"/&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>This page has a suggestion for <em>adding</em> attributes but doesn't detail a way to map a current attribute with a function (this way would make that very hard):
  <a href="http://www.scalaclass.com/book/export/html/1" rel="noreferrer">http://www.scalaclass.com/book/export/html/1</a></p>
  
  <p>What I've come up with is to manually create the XML (non-scala) linked-list... something like:</p>
  
  <pre><code>// a typical match case for running thru XML elements:
  case  Elem(prefix, e, attributes, scope, children @ _*) =&gt; {
   var newAttribs = attributes
   for(attr &lt;- newAttribs)  attr.key match {
    case "attr1" =&gt; newAttribs = attribs.append(new UnprefixedAttribute("attr1", (attr.value.head.text.toFloat * 2.0f).toString, attr.next))
    case "attr2" =&gt; newAttribs = attribs.append(new UnprefixedAttribute("attr2", (attr.value.head.text.toFloat * 2.0f).toString, attr.next))
    case _ =&gt;
   }
   Elem(prefix, e, newAttribs, scope, updateSubNode(children) : _*)  // set new attribs and process the child elements
  }
  </code></pre>
  
  <p>Its hideous, wordy, and needlessly re-orders the attributes in the output, which is bad for my current project due to some bad client code.  Is there a scala-esque way to do this?</p>