Jump to content

PHP and XML help


RyuMaster

Recommended Posts

Hi! My head already burns - I'm new to PHP and XML, so I just hope some one will help!

I have xml files, which looks like this:

 

<toplevel>

<username id ="Jonh">

    <playersname name ="Kostik">

      <starcolor>3</starcolor>

      <levels>19</levels>

    </playersname>

    <playersname name ="Mostik">

      <starcolor>1</starcolor>

        <levels>19</levels>

    </playersname>

</username>

</toplevel>

 

My flash file passes 4 parameters to the scipt - UserName, PlayersName, StarColor and LessonsFinished.

 

  What I'm trying to do:

Php receives parameters. He loads user.xml and checks. If Username already present, he checks all playersname for that users. If playersname present, scipt updates starcolor and lessons, and writes it to the file.

If User present, but players is not, script crates new nodes for new players. If users is not present, script creates new user with players nodes near end of the file. I know, i is probably very hard and large script, so I wil laprreciate any help and pointers. Here is what I made so far, it is half finished:

 

<?php

$UsersName=$_POST['UsersName'];

$index = 0;

$PlayersName=$_POST['PlayersName'];

$StarsColor=$_POST['StarsColor'];

$SLessonsComplete=$_POST['LessonsComplete'];

$dom=new DOMDocument();

$dom->load('users.xml');

$dom->formatOutput = true;

echo $dom->saveXML(); // show before file

$allnodes = $dom->getElementsByTagName('username');

foreach ($allnodes as $node)

{

    if ($node->nodeName=='username' and $node->getAttribute('id')==UsersName)

    {

          $allplayers = $dom->getElementsByTagName('playersname');

          foreach ($allplayers as $player)

          {

            if ($player->nodeName=='playersname' and  $node->getAttribute('id')==PlayersName)

              {

            ???????

              }

 

?????

}

index++;

}

echo $dom->saveXML(); //show after file

$dom->save('users.xml');

exit;

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.