Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    92
    Thanks
    4
    Thanked 0 Times in 0 Posts

    xmlToArray function not working - generating errors and breaking code

    --- EDIT ---
    I Figured out the issue . . . and it is not related to anything here so disregard!
    --- EDIT ---

    I retrieve data from an XML file that is pasted in a text box. I'm trying to use a simple method I stumbled across online to convert the XML to an array that easily accessible. It seems like a dirty way of doing it so if anyone knows of an effective XML parser that will result in an array, please let me know!

    Here is the function itself:
    PHP Code:
    <?php
        
    function xmlToArray($xml) {
            
    $array json_decode(json_encode((array) simplexml_load_string($xml)),1);
            return 
    $array;
        }
    ?>

    Here are the errors generated on the page. I believe the undefined index errors are a result of the XML not being properly parsed and therefore none of the variables are being set.
    Code:
    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : String not started expecting ' or " in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Malformed declaration expecting version in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Blank needed here in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : parsing XML declaration: '?>' expected in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 4: parser error : AttValue: " or ' expected in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: <rss version=\"0.91\"> in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 4: parser error : attributes construct error in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: <rss version=\"0.91\"> in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 4: parser error : Couldn't find end of Start Tag rss line 4 in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: <rss version=\"0.91\"> in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 4: parser error : Extra content at the end of the document in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: <rss version=\"0.91\"> in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/styles2/public_html/systemscan/scripts/php/fnc.xmlToArray.php on line 3
    
    Notice: Undefined index: channel in /home/styles2/public_html/systemscan/process.php on line 52
    
    Warning: Invalid argument supplied for foreach() in /home/styles2/public_html/systemscan/process.php on line 54
    
    Notice: Undefined index: channel in /home/styles2/public_html/systemscan/process.php on line 73
    
    Notice: Undefined index: channel in /home/styles2/public_html/systemscan/process.php on line 74
    
    Notice: Undefined index: channel in /home/styles2/public_html/systemscan/process.php on line 75
    
    Notice: Undefined index: channel in /home/styles2/public_html/systemscan/process.php on line 76
    
    Notice: Undefined index: channel in /home/styles2/public_html/systemscan/process.php on line 77
    
    Warning: Invalid argument supplied for foreach() in /home/styles2/public_html/systemscan/process.php on line 80
    Last edited by Styles2304; 04-29-2013 at 01:58 AM.


 

Posting Permissions

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