title: Using xml2 to add child node with an attribute
body: <p>I'm using R's <code>xml2</code> package to edit an XML document. I'd like to add a node with a specific XML attribute, but I don't seem to understand the syntax of <code>add_child_node</code>.</p>
  <p>Adding a node works great:</p>
  <pre class="lang-r prettyprint-override"><code>library(xml2)
  my_xml &lt;- read_xml(&quot;&lt;fruits&gt;&lt;apple/&gt;&lt;banana/&gt;&lt;/fruits&gt;&quot;)
  xml_add_child(.x = my_xml, .value = &quot;coconut&quot;)
  my_xml
  
  # {xml_document}
  # &lt;fruits&gt;
  # [1] &lt;apple/&gt;
  # [2] &lt;banana/&gt;
  # [3] &lt;coconut/&gt;
  </code></pre>
  <p>and according my understanding of the documentation, I should be able to add an attribute to the node by using the ellipsis argument to provide a named vector of text:</p>
  <pre class="lang-r prettyprint-override"><code>my_xml &lt;- read_xml(&quot;&lt;fruits&gt;&lt;apple/&gt;&lt;banana/&gt;&lt;/fruits&gt;&quot;)
  xml_add_child(.x = my_xml, .value = &quot;coconut&quot;, c(id=&quot;new&quot;))
  my_xml
  
  # {xml_document}
  # &lt;fruits&gt;
  # [1] &lt;apple/&gt;
  # [2] &lt;banana/&gt;
  # [3] &lt;coconut&gt;new&lt;/coconut&gt;
  </code></pre>
  <p>However, this appears to simply insert the text into the node, as it does when the text is unnamed. The attribute doesn't show up at all.</p>
  <p>What I'd like to get is this:</p>
  <pre><code># {xml_document}
  # &lt;fruits&gt;
  # [1] &lt;apple/&gt;
  # [2] &lt;banana/&gt;
  # [3] &lt;coconut id=&quot;new&quot;/&gt;
  </code></pre>
  <p>Any thoughts? I'm aware that I can set attributes manually after the fact using <code>xml_attr&lt;-</code> but my use case doesn't support that method very well.</p>
  <p>Snapshot of the documentation for anyone who doesn't want to pull it up:
  <a href="https://i.stack.imgur.com/gfweq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gfweq.png" alt="Documentation from ?xml2::add_child_node" /></a></p>