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

  • Home
  • SEARCH
  • 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 56349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:31:14+00:00 2026-05-10T17:31:14+00:00

Here’s the XML file i’m working on: <list> <activity>swimming</activity> <activity>running</activity> <activity>soccer</activity> </list> The index.php,

  • 0

Here’s the XML file i’m working on:

<list>     <activity>swimming</activity>     <activity>running</activity>     <activity>soccer</activity> </list> 

The index.php, page that shows the list of activities with checkboxes, a button to delete the checked activities, and a field to add new activities:

<html> <head></head> <body> <?php     $xmldoc = new DOMDocument();     $xmldoc->load('sample.xml', LIBXML_NOBLANKS);      $count = 0;      $activities = $xmldoc->firstChild->firstChild;     //prints the list of activities, with checkboxes on the left for each item     //the $count variable is the id to each entry     if($activities!=null){         echo '<form name=\'erase\' action=\'delete.php\' method=\'post\'>' . '\n';         while($activities!=null){             $count++;             echo '    <input type=\'checkbox\' name=\'activity[]\' value=\'$count\'/>';             echo ' '.$activities->textContent.'<br/>'.'\n';             $activities = $activities->nextSibling;         }         echo '    <input type=\'submit\' value=\'erase selected\'>';         echo '</form>';     } ?> //section used for inserting new entries. this feature is working as expected. <form name='input' action='insert.php' method='post'>     insert activity:     <input type='text name='activity'/>     <input type='submit' value='send'/>     <br/> </form> </body> </html> 

the delete.php, which is not working as expected:

<?php     $xmldoc = new DOMDocument();     $xmldoc->load('sample.xml', LIBXML_NOBLANKS);      $atvID = $_POST['activity'];      foreach($atvID as $id){         $delnode = $xmldoc->getElementsByTagName('activity');         $xmldoc->firstChild->removeChild($delnode->item($id));     }      $xmldoc->save('sample.xml'); ?> 

I’ve tested the deletion routine without the loop, using an hard-coded arbitrary id, and it worked. I also tested the $atvID array, and it printed the selected id numbers correctly. When it is inside the loop, here’s the error it outputs:

Catchable fatal error: Argument 1 passed to DOMNode::removeChild() must be an instance of DOMNode, null given in /directorypath/delete.php on line 9

What is wrong with my code?

  • 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. 2026-05-10T17:31:15+00:00Added an answer on May 10, 2026 at 5:31 pm

    the DOMNodeList items are indexed starting with 0; You need to move the $count++ to the end of the while loop in the output step.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I bet this Code Project page will get you headed… May 11, 2026 at 10:10 am
  • added an answer Welcome to the patterns & practices Team Development with Visual… May 11, 2026 at 10:10 am
  • added an answer It should be possible to cast (explicitly or implicitly) the… May 11, 2026 at 10:10 am

Related Questions

Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here is my code, which takes two version identifiers in the form 1, 5,
Here's a coding problem for those that like this kind of thing. Let's see
Here is the scenario: I'm writing an app that will watch for any changes
Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here we go again, the old argument still arises... Would we better have a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.