tags:

views:

315

answers:

1

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

$doc->addChild('myToken');

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

<myToken/>

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:

<myToken></myToken>

The question is, how do I do this, outside of running the generated XML through a preg_replace?

+1  A: 

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.

Piskvor
Or just hand coding it.
Stephen