Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7776613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:55:45+00:00 2026-06-01T17:55:45+00:00

I created an ios app that parses an xml document. If a user logs

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:55:46+00:00Added an answer on June 1, 2026 at 5:55 pm
    <?php 
    /*
     * @source_file -- source to your xml document
     * @node_to_remove -- your node
     * Note this will remove an entire user from the source file if the argument (node_to_remove)
       matches a nodes node value
     *
     */
    function newFunction($source_file,$node_to_remove) {
        $xml = new DOMDocument();
        $xml->load($source_file);
        $xml->preserveWhiteSpace = false;
        $xml->formatOutput = true; 
        foreach ($xml->getElementsByTagName('users') as $users ) 
        {
            foreach($users->getElementsByTagName('user') as $user) {
    
                $first_name = $user->getElementsByTagName('fname')->item(0);
    
                if($first_name->nodeValue == $node_to_remove) {
    
    
                    $users->removeChild($users->getElementsByTagName('user')->item(0));
    
                }
    
            }
    
        }
    
        $result = $xml->saveXML();
    
        return $result;
    
    }
    
    
    echo newFunction('xml.xml','lname1');
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an iOS app that requires a user to link his/her Dropbox
i´ve just created an iOS app that contains lots of media. Now i just
Our iOS app has a Web View that is rendering pages from file: URLs.
I'm trying to make an iOS app that allows the user to create an
Our company created an iOS app that has an iPhone version and an iPad
I have a singleton object in iOS that when instantiated parses a CSV file
I created an iOS app that allowed me to enter data into database and
I'm looking to create a simple iOS app that displays the current water level
I want to create a simple desktop admin application for an IOS app that
I have an iOS app I created as a view-based app in xCode. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.