I have heard many things about php retrieving information from pearl and mysql. But I have a different function in mind I would like to be able to access XML. How would I do such a thing? Say an XML document like this

<games>
 <game>
   <name>High Low Face Value</name>
   <author>A two player High low game (intense, high buzz factor)</author>
   <rule>
     Now the to play you must be a person of drinking age. You must also have     
some cards, one other person, and beer!!!! (of coarse silly) </rule> <example> -= GamePlay: -= A deck of cards is shuffled and one card is delt to the the other player. The player then must choose if the card the dealer will lay down next is going to be higher or lower then the first. If the player guesses incorrectly they then drink the face value of every card the pile. -= Any cards equal to the card already laid down is a loss. -= Each player has to go through the whole deck. -= You must drink all the face value of every card showing when you guess incorrectly. -= When a person guesses incorrectly a new pile is started. As always drink responsibly and never drink and drive. </example> </game> </games>

I took XML in school and would like to implement it considering its versatility. I would figue I would need some type of script and then I would just echo the variables inside a table on a web page. But how? how do I call on each element? because I would also like to be able to write to it using a seperate script. That is if I am not home and need to publish a story or finding! Thanks In advance

    <?php
    $xml = simplexml_load_file('path to xml');
    
    echo $xml->game->name."<br>";
    echo $xml->game->author."<br>";
    echo $xml->game->rule."<br>";
    echo $xml->game->example."<br>";
    
    
    ?>

      you mean

      echo $xml->games->game->rule."<br>";

      also in that XML file I have multiple records of <game> under the parent <games> about 10 in all. How do I display on <game> record at a time?

        MarkBad311 wrote:

        you mean

        echo $xml->games->game->rule."<br>";

        No I meant what I wrote Did you test it?

        also in that XML file I have multiple records of <game> under the parent <games> about 10 in all. How do I display on <game> record at a time?

        With a foreach() like

        <?php
        
        $xml = simplexml_load_file('games.xml');
        foreach ($xml->game as $item) {
        
        
        echo $item->name."<br>";
        echo $item->author."<br>";
        echo $item->rule."<br>";
        echo $item->example."<br>";
        
        }
        
        ?>

        Again tested!

          I'm doing something similar here. How do you chose a specific game to display?

            7 days later

            you can use the ID attribute in the XML file to match up with every query? just guessing really I took XML and related technologies but php wasn't in the book at all so.

              Write a Reply...