I don't know why in this PHP function when I open the XML file with SimpleXMLElement I am able to get the nodes. But when I create a new DOMdocument and load the XML file into it, the DOMdocument isn't created at all, so I cannot get the nodes.


function get_nodes() {
// load SimpleXML
/* $nodes = new SimpleXMLElement('communities.xml', null, true); */

$dom = new DOMDocument();

$dom->formatOutput = true; 
$dom->preserveWhiteSpace = true;

// get document element  

$xpath = new DOMXPath($dom);
$nodes = $xpath->query("//COMMUNITY");

$nnodes = sizeof($nodes);
echo "<script type='text/javascript'> alert('Got ".$nnodes." nodes'); </script>";

foreach($nodes as $node) // loop through 

        echo "<div id = '".$node['ID']."' class= 'comdiv ui-widget-content' style = 'top: ".$node->TOP."; left: ".$node->LEFT."; width: ".$node->WIDTH."; 

height: ".$node->HEIGHT.";'> \n";            echo "   <p class = 'comhdr editableText ui-widget-header'>".$node->NAME."</p>\n";

        echo "   <a href='#' onClick=\"delete_div('".$node['ID']."');\">Delete</a>&nbsp;&nbsp;\n";
        echo "   <a href='#' onClick=\"add_url('".$node['ID']."');\">Add URL</a>&nbsp;&nbsp;\n";

        echo "</div> \n";

        echo "<script type='text/javascript'>\n";
        echo "  $('#".$node['ID']."').resizable();\n";
        echo "  $('#".$node['ID']."').draggable();\n";
        echo "  $('#".$node['ID']."').draggable('option', 'handle', '.comhdr');\n";
        echo "</script>\n";

        echo "<script type='text/javascript'>\n";
        echo " 	$('.comhdr').editableText();\n";
        echo "</script>\n";


echo get_nodes();