The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 5 of 5

Thread: XML Parsing using PHP {Easy} Not importing all data from xml file?

  1. #1

    XML Parsing using PHP {Easy} Not importing all data from xml file?

    Hi everyone,

    I am very new to php. I've just read the tutorial on importing xml with php. I've uploaded and ran the file although it only displays some of the xml. I have no idea why it doesn't load all the information through.

    The feed is: http://xboxapi.duncanmackenzie.net/g...rTag=MAdEinUk1
    My file is located at: http://www.davidpaulrosser.co.uk/xml_beginner.php

    My script is:

    Code:
    <?php
    // The XML file that you wish to be parsed
    $file = "http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=MAdEinUK1";
    
    // This function tells the parser what to do with the data once it reaches the contents
    // that appear between tags.
    function contents($parser, $data){
        echo $data;
    }
    
    // This function tells the parser to place a <b> where it finds a start tag.
    function startTag($parser, $data){
        echo "<$data>";
    }
    
    // And this function tells the parser to replace the end tags with "<b><br />"
    function endTag($parser, $data){
        echo "</$data>";
    }
    
    // These lines create the parser and then set the functions for the parser to use when
    // reading the document.
    $xml_parser = xml_parser_create();
    
    // Sets the functions for start and end tags
    xml_set_element_handler($xml_parser, "startTag", "endTag");
    // Sets the function for the contents/data
    xml_set_character_data_handler($xml_parser, "contents");
    
    // Opens the file for reading
    $fp = fopen($file, "r");
    
    // Read the file and save its contents as the variable "data"
    $data = fread($fp, 8192);
    
    // This if statement does two things. 1) it parses the document according to our 
    // functions created above. 2) If the parse fails for some reason it returns an
    // error message and also tells us which line the error occured at.
    if(!(xml_parse($xml_parser, $data, feof($fp)))){
        die("Error on line " . xml_get_current_line_number($xml_parser));
    }
    
    // Free the memory used to create the parser
    xml_parser_free($xml_parser);
    
    // Close the file when you're done reading it
    fclose($fp);
    ?>
    It says something in the tutorial about the third function parsing the data until it reaches the end of the file? Please can someone shed some light on this.

    Thank you,

    David Rosser

  2. #2
    Are you sure the xml file is valid?

    Also xml errors aren't really php errors(go figure) so you have to use a function to retrieve them http://us2.php.net/manual/en/functio...get-errors.php or maybe http://www.php.net/manual/en/functio...error-code.php

  3. #3
    Are you sure the xml file is valid?

    Also xml errors aren't really php errors(go figure) so you have to use a function to retrieve them http://us2.php.net/manual/en/functio...get-errors.php or maybe http://www.php.net/manual/en/functio...error-code.php

  4. #4
    Yeah im sure it is. I was feeding it directly into flash. Everything was working fine until I tried it online. The guys cross domain policy has a typo so it won't run online properly. This is my workaround of it.

    The file: http://xboxapi.duncanmackenzie.net/g...rTag=MAdEinUk1
    loads up about half way in the php script: http://www.davidpaulrosser.co.uk/xml_beginner.php

    Code:
    <XBOXINFO>
      <ACCOUNTSTATUS>Gold</ACCOUNTSTATUS>
      <PRESENCEINFO>
        <VALID>true</VALID>
        <INFO>Last seen 09/17/09   playing Xbox.com</INFO>
        <INFO2></INFO2>
        <LASTSEEN>2009-09-17T15:26:15+00:00</LASTSEEN>
        <ONLINE>false</ONLINE>
        <STATUSTEXT>Offline</STATUSTEXT>
        <TITLE>Xbox.com</TITLE>
      </PRESENCEINFO>
      <STATE>Valid</STATE>
      <GAMERTAG>MAdEinUK1</GAMERTAG>
      <PROFILEURL>http://live.xbox.com/member/MAdEinUK1</PROFILEURL>
      <TILEURL>http://avatar.xboxlive.com/avatar/MAdEinUK1/avatarpic-l.png</TILEURL>
      <COUNTRY>United Kingdom</COUNTRY>
      <REPUTATION>99.9291</REPUTATION>
      <BIO></BIO>
      <LOCATION>Brighton, UK</LOCATION>
      <REPUTATIONIMAGEURL>http://live.xbox.com/xweb/lib/images/gc_repstars_external_20.gif</REPUTATIONIMAGEURL>
      <GAMERSCORE>3793</GAMERSCORE>
      <ZONE>Pro</ZONE>
      <RECENTGAMES>
        <XBOXUSERGAMEINFO>
          <GAME>
            <GAMEID>%09%5d%3adh)k%3f%7f%06</GAMEID>
            <NAME>Skate 2</NAME>
            <TOTALACHIEVEMENTS>60</TOTALACHIEVEMENTS>
            <TOTALGAMERSCORE>1500</TOTALGAMERSCORE>
            <IMAGE32URL>http://tiles.xbox.com/tiles/uY/Lt/0Gdsb2JgbA9ECgQNGwEfVlglL2ljb24vMC84MDAwIAABAAAAAP-CgqY=.jpg</IMAGE32URL>
            <IMAGE64URL>http://tiles.xbox.com/tiles/1i/zZ/12dsb2JhbC9ECgQNGwEfVlglL2ljb24vMC84MDAwAAAAAAAAAPj2LMk=.jpg</IMAGE64URL>
          </GAME>
          <LASTPLAYED>2009-09-03T17:17:39+00:00</LASTPLAYED>
          <ACHIEVEMENTS>42</ACHIEVEMENTS>
          <GAMERSCORE>1080</GAMERSCORE>
          <DETAILSURL>http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3adh)k%3f%7f%06&compareTo=MAdEinUK1</DETAILSURL>
        </XBOXUSERGAMEINFO>
        <XBOXUSERGAMEINFO>
          <GAME>
            <GAMEID>%09%5d%3bhe)j2%7c%7e</GAMEID>
            <NAME>Family Game Night</NAME>
            <TOTALACHIEVEMENTS>70</TOTALACHIEVEMENTS>
            <TOTALGAMERSCORE>1400</TOTALGAMERSCORE>
            <IMAGE32URL>http://tiles.xbox.com/tiles/Id/VM/12dsb2JgbA9ECgUAGwEfV1dSL2ljb24vMC84MDAwIAABAAAAAPhj1T4=.jpg</IMAGE32URL>
            <IMAGE64URL>http://tiles.xbox.com/tiles/Tn/t4/0Gdsb2JhbC9ECgUAGwEfV1dSL2ljb24vMC84MDAwAAAAAAAAAP9Xe1E=.jpg</IMAGE64URL>
          </GAME>
          <LASTPLAYED>2009-09-01T18:14:35+00:00</LASTPLAYED>
          <ACHIEVEMENTS>7</ACHIEVEMENTS>
          <GAMERSCORE>110</GAMERSCORE>
          <DETAILSURL>http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3bhe)j2%7c%7e&compareTo=MAdEinUK1</DETAILSURL>
        </XBOXUSERGAMEINFO>
        <XBOXUSERGAMEINFO>
          <GAME>
            <GAMEID>%09%5d%3a%15%18*iN%0a%02</GAMEID>
            <NAME>Gears
    Il try those php functions tomorrow. Do you have any idea why it only loads up half the document though?

    I was trying another php script but I don't understand how to modify it. This loads up the xml fine: http://www.davidpaulrosser.co.uk/testNN.php

  5. #5
    Resolved!

    Code:

    Code:
    <?php
        $tag = $_GET['GamerTag'];
        echo file_get_contents("http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=$tag");
    ?>

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012