Results 1 to 6 of 6

Thread: XML Parsed as Empty

  1. #1
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default XML Parsed as Empty

    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:
    Code:
    object(DOMDocument)#1 (0) {
    }
    Here's the XML:
    Code:
    <?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.
    Last edited by Jesdisciple; 06-08-2009 at 11:58 PM.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  2. #2
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    Able to use SimpleXML?

    PHP Code:
    //$filename = 'myXML.xml';
    $xml_data = new SimpleXMLElement($filename0true);

    //var_dump($xml_data); 

  3. The Following User Says Thank You to techietim For This Useful Post:

    Jesdisciple (06-08-2009)

  4. #3
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    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.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  5. #4
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    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.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  6. #5
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    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.)
    Code:
    #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.
    Code:
    	$nodes = array_fill_keys(scandir($_SERVER['DOCUMENT_ROOT'] . $dir), array());
    Thanks for trying to help.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  7. #6
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Never mind about those errors; they were my fault, but the DOM objects are still empty.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •