I created an ios app that parses an xml document. If a user logs in, their information will be added to the xml file. I would like to be able to remove a user if they are logging out or cancelling their logins. Essentially, I need to figure out how to delete an xml object (a user, in this case) that looks like this:
<users>
<user>
<fname>fname1</fname>
<lname>lname1</lname>
</user>
<user>
<fname>fname2</fname>
<lname>lname2</lname>
</user>
</users>
For example, I may want to remove a user based on the last name, which will always be unique in my case… This is the php that I have so far, but I am completely open to suggestions on doing it a different way
$deletefname = $row['fname'];
$deletelname = $row['lname'];
$deleteimageurl = $row['imageURL'];
$xmlUrl = "thefile.xml"; // XML
$xmlStr = file_get_contents($xmlUrl);
$xml = new SimpleXMLElement($xmlStr);
foreach($xml->users as $user)
{
if($user[$fname] == $deletefname) {
$xml=dom_import_simplexml($user);
$xml->parentNode->removeChild($xml);
}
}
$xml->asXML('newfile.xml');
echo $xml;
I am very bad with php, and I took this code from someone else. Not 100% sure how it works.
Thanks for your help.
1 Answer