PHP and XML help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RyuMaster
    New Member
    • Mar 2008
    • 1

    PHP and XML help

    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:

    Code:
    <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 will aprreciate any help and pointers. Here is what I made so far, it is half finished:

    [PHP]<?php
    $UsersName=$_PO ST['UsersName'];
    $index = 0;
    $PlayersName=$_ POST['PlayersName'];
    $StarsColor=$_P OST['StarsColor'];
    $SLessonsComple te=$_POST['LessonsComplet e'];
    $dom=new DOMDocument();
    $dom->load('users.xm l');
    $dom->formatOutput = true;
    echo $dom->saveXML(); // show before file
    $allnodes = $dom->getElementsByT agName('usernam e');
    foreach ($allnodes as $node)
    {
    if ($node->nodeName=='use rname' and $node->getAttribute(' id')==UsersName )
    {
    $allplayers = $dom->getElementsByT agName('players name');
    foreach ($allplayers as $player)
    {
    if ($player->nodeName=='pla yersname' and $node->getAttribute(' id')==PlayersNa me)
    {
    x=xmlDoc.getEle mentsByTagName( "topleve;")[index];
    y=x.childNodes[0];
    }


    $val=$node->getAttribute(' value') . ' updated';
    $node->setAttribute ( 'value', $val );
    }
    index++;
    }
    echo $dom->saveXML(); //show after file
    $dom->save('users.xm l');
    exit;
    ?>
    [/PHP]
Working...