I have an XML string that sometimes has empty nodes. When parsing this with simplexml_load_string the parser interprets any empty nodes (example <node></node>) to be an empty SimpleXMLElement. I actually would prefer these come through as an empty string, or are just omitted entirely.
I've tried using LIBXML_NOBLANKS as shown below, but it seems to have no effect. Here's some code that demonstrates the situation. the node "p2" is empty:
$xml = "<xml><p1>1</p1><p2></p2><p3>3</p3></xml>";
$obj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOBLANKS);
header("Content-type: text/plain");
echo "STRING\n-----\n" . $xml;
echo "\n\nOBJ\n---\n" . print_r($obj,1);
echo "\n\nJSON\n----\n" . json_encode($obj);