Welcome to Tactical Gamer

+ Reply to Thread
Results 1 to 5 of 5
Discussion: General Forums / Hardware & Software Discussion - PHP: XML Reader Question - I am trying to grab certain attributes from an xml page. It works fine on
  1. #1

    orion808's Avatar

    Join Date
    Nov 2004
    Location
    Florida, US
    Age
    31
    Posts
    1,140

    PHP: XML Reader Question

    I am trying to grab certain attributes from an xml page. It works fine on my own desktop comp with a localhost server. When I upload to my website, which uses mySQL, it fails. I am new to php and seem to be stuck because it doesn't output an error.

    Here is the code: (this was copy/pasted from somewhere on the net and edited by me to fit my needs)

    Code:
    $xml = new XMLReader();
        $xml->open($new_link); // Declare and open the xml file
        $xml->setParserProperty(2,true); // This seems a little unclear to me - but it worked :)
    
        while ($xml->read()) {
    		echo 'test1';
            switch ($xml->name) {
            case "name":
                $xml->read();
                $conf["name"] = $xml->value;
    			$item_name = $conf["name"]; 
    			echo $item_name;
                $xml->read();
                break;
            case "quality":
                $xml->read();
                $conf["quality"] = $xml->value;
    			$raw_quality = $conf["quality"];
    			if ($raw_quality == 'Common')
    				$item_quality = 1;
    			elseif ($raw_quality == 'Uncommon')
    				$item_quality = 2;
    			elseif ($raw_quality == 'Rare')
    				$item_quality = 3;
    			elseif ($raw_quality == 'Epic')
    				$item_quality = 4;
    			elseif ($raw_quality == 'Legendary')
    				$item_quality = 5;
    			else 
    				$item_quality = 0;
                $xml->read();
                break;
            case "subclass":
                $xml->read();
                $conf["subclass"] = $xml->value;
    			$item_subclass = $conf["subclass"];
    			echo $item_subclass;
                $xml->read();
                break;
    		case "inventorySlot":
                $xml->read();
                $conf["inventorySlot"] = $xml->value;
    			$item_slot = $conf["inventorySlot"]; 
    			echo $item_slot;
                $xml->read();
                break;
    		case "link":
                $xml->read();
                $conf["link"] = $xml->value;
    			$item_link = $conf["link"];
    			echo $item_link;
                $xml->read();
                break;
    		echo "$xml->read()";
            }
        }
    
        $xml->close();
    After this, my code grabs the new $item_xxxx variables and inserts them into the database. Even if I try to echo the variables after this XML Reader, they won't show. Again, I have no issues on my home computer with localhost server. Is there something I am missing? Or is there abetter way to do this?


  2.  
  3. #2

    orion808's Avatar

    Join Date
    Nov 2004
    Location
    Florida, US
    Age
    31
    Posts
    1,140

    Re: PHP: XML Reader Question

    The user inputs a number, hits submit, the xml reader locates the xml with that number on a certain website. Then it reads it and outputs variables for the php to save.

    One thing to note....when on the internet (where it is breaking and not working) it also makes the footer disappear after the user inputs the number and hits submit


  4.  
  5. #3

    orion808's Avatar

    Join Date
    Nov 2004
    Location
    Florida, US
    Age
    31
    Posts
    1,140

    Re: PHP: XML Reader Question

    PHP 5 introduced XMLReader, a new class for reading Extensible Markup Language (XML).
    Seems I might have an older version. After checking my phpinfo, I have v 4.3.11 through my provider (Yahoo).

    I've emailed them, but expecting the classic response of a 'not at this time' attitude. Any suggestions?
    Last edited by orion808; 08-11-2008 at 10:19 PM.


  6.  

     
  7. #4


    Apophis's Avatar

    Join Date
    Oct 2001
    Location
    Northeast, USA
    Age
    39
    Posts
    9,963
    Blog Entries
    10

    Re: PHP: XML Reader Question

    PHP4 is officially end-of-life. Hopefully your provider will upgrade soon.

    Diplomacy is the art of saying "good doggie" while looking for a bigger stick.

  8.  
  9. #5

    orion808's Avatar

    Join Date
    Nov 2004
    Location
    Florida, US
    Age
    31
    Posts
    1,140

    Re: PHP: XML Reader Question

    Email response said not now, and not soon....so I'll be looking for another provider. Seems silly too. I'm just learning php and I can see the difference in the two.


  10.  

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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


  
 

Back to top