RyuMaster Posted March 7, 2008 Share Posted March 7, 2008 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; ?> Quote Link to comment Share on other sites More sharing options...
RyuMaster Posted March 7, 2008 Author Share Posted March 7, 2008 Oh, probably this really is the hard one =( Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.