Announcement

Collapse
No announcement yet.

PHP: XML Reader Question

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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, 09:19 PM.

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment

          Connect

          Collapse

          TeamSpeak 3 Server

          Collapse

          Advertisement

          Collapse

          Twitter Feed

          Collapse

          Working...
          X