<p>I'm building an XML document with PHP's SimpleXML extension, and I'm adding a token to the file:</p>

<pre><code>$doc-&gt;addChild('myToken');
</code></pre>

<p>This generates (what I know as) a self-closing or single tag:</p>

<pre><code>&lt;myToken/&gt;
</code></pre>

<p>However, the aging web-service I'm communicating with is tripping all over self-closing tags, so I need to have a separate opening and closing tag:</p>

<pre><code>&lt;myToken&gt;&lt;/myToken&gt;
</code></pre>

<p>The question is, how do I do this, outside of running the generated XML through a <strong>preg_replace</strong>?</p>

From the documentation at
SimpleXMLElement->__construct
and
LibXML Predefined Constants
, I think this should work:
```
```
<?php
$sxe = new SimpleXMLElement($someData, LIBXML_NOEMPTYTAG);

// some processing here

$out = $sxe->asXML();
?>
```
```
Try that and see if it works. Otherwise, I'm afraid, it's preg_replace-land.