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; ?> Link to comment https://forums.phpfreaks.com/topic/94860-php-and-xml-help/ 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 =( Link to comment https://forums.phpfreaks.com/topic/94860-php-and-xml-help/#findComment-486336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.