Log in

View Full Version : XML Parsed as Empty



Jesdisciple
06-08-2009, 02:20 PM
I think I actually have a real problem this time. I have an XML file which PHP parses as being empty. When I var_dump the DOMDocument, I just get this:
object(DOMDocument)#1 (0) {
}

Here's the XML:
<?xml version="1.0"?>
<directory indexable="yes">
<directory name="lib" indexable="yes" />
<directory name="projects" indexable="yes" />
<file name="index.html" indexable="yes"/>
<file name="Index.php" indexable="yes"/>
<file name="phpinfo.php" indexable="yes"/>
<file name="test.js" indexable="no"/>
<file name="test.php" indexable="no"/>
</directory>

EDIT: I've discovered that I get the same result if I instead call loadXML on the file's contents. However, I get NULL when I test similar code by itself.

Help, please.

techietim
06-08-2009, 07:18 PM
Able to use SimpleXML?



//$filename = 'myXML.xml';
$xml_data = new SimpleXMLElement($filename, 0, true);

//var_dump($xml_data);

Jesdisciple
06-08-2009, 08:46 PM
Why didn't I think of that? Yeah, it works - so thanks!

I've also asked for help on the Ubuntu Forums, so if anyone wants to get an update either PM me or reply here. If the topic is very old by now, it's probably more polite to PM me.

Jesdisciple
06-09-2009, 12:00 AM
Woops, I was wrong. SimpleXML is inadequate for at least one thing I was doing with DOM. I was importing and appending a node (the document element of another document), and SimpleXML can't do either.

Does anyone have any idea where I might look in my system for this bug? Thanks.

Jesdisciple
06-09-2009, 05:20 AM
I just set an error-handler for my pages and suddenly got a flood of errors, each of them either E_WARNING (2), E_NOTICE (8), or E_RECOVERABLE_ERROR (4096). Here is the first line of the interesting backtrace minus the context, which was a huge var_dump. (Strangely, all the contexts had the two parameter values switched between their identifiers.)
#0 handle_error(4096, Object of class DOMElement could not be converted to string, /home/coder/www/lib/PHP/files/file_list.php, 329, ...) called at [/home/coder/www/lib/PHP/files/file_list.php:329]

Here is line 329; $dir is the one which the DOMElement ($element) gets switched with. I tried using $element instead of $dir here, but that just doubled the number of 4096s I saw.
$nodes = array_fill_keys(scandir($_SERVER['DOCUMENT_ROOT'] . $dir), array());Thanks for trying to help. :)

Jesdisciple
06-09-2009, 05:38 PM
Never mind about those errors; they were my fault, but the DOM objects are still empty.