title: How to edit specific elements in XML file using HXT?
body: <p>In short, here is what I want to accomplish:</p>
  
  <p><code>"foo.xml"</code>:
  </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;foo&gt;
    &lt;bar&gt;
      &lt;baz&gt;
        &lt;a&gt;foo&lt;/a&gt;
        &lt;a&gt;bar&lt;/a&gt;
        &lt;a&gt;baz&lt;/a&gt;
      &lt;/baz&gt;
    &lt;/bar&gt;
  &lt;/foo&gt;
  </code></pre>
  
  <p>expected result (contents of <code>"bar.xml"</code>):</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;foo&gt;
    &lt;bar&gt;
      &lt;baz&gt;
        &lt;a&gt;foo!&lt;/a&gt;
        &lt;a&gt;bar!&lt;/a&gt;
        &lt;a&gt;baz!&lt;/a&gt;
      &lt;/baz&gt;
    &lt;/bar&gt;
  &lt;/foo&gt;
  </code></pre>
  
  <p>...my attempt to approach the problem:
  </p>
  
  <pre><code>module Main (main) where
  
  import Control.Monad
  
  import Control.Arrow.ArrowTree
  import Text.XML.HXT.Core
  
  main :: IO ()
  main = void . runX $ readDocument [] "foo.xml" &gt;&gt;&gt;
         applic &gt;&gt;&gt; writeDocument [withIndent yes] "bar.xml"
  
  applic :: IOSArrow XmlTree XmlTree
  applic = getChildren &gt;&gt;&gt; hasName "foo"
  --       ^^ because of extra root node (?)
           /&gt; hasName "bar" /&gt; hasName "baz" /&gt; hasName "a" &gt;&gt;&gt; changeText excl
  
  excl :: String -&gt; String
  excl = (++ "!")
  </code></pre>
  
  <p><strong>Question:</strong> How to directly edit just selected elements without changing/removing their root elements? Also note that this program doesn't create <code>"bar.xml"</code> file, so something is definitely wrong. Tracing shows that after applying <code>applic</code> arrow, the document consists of three <code>a</code> elements (<code>"foo"</code>, <code>"bar"</code>, and <code>"baz"</code>; without exclamation points).</p>