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 9019777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:51:29+00:00 2026-06-16T04:51:29+00:00

I am trying to remove the parent node of <wcccanumber> from my xml, if

  • 0

I am trying to remove the parent node of <wcccanumber> from my xml, if it’s content matches a certain criterion, but it keeps just removing the one node <wcccanumber>. How do I remove the whole parent node?

Heres my code:

$xml = new SimpleXMLElement('<xml/>');

if (file_exists("xml/units/E01.xml")) {

    $xml = simplexml_load_file("xml/units/E01.xml");

    echo "File exists";
    echo "</br>";

    $wcccanumber = "121202482";

    foreach ($xml->call->wcccanumber as $call) {
        if ($call == $wcccanumber) {
            $dom = dom_import_simplexml($call);
            $dom->parentNode->removeChild($dom);

            $fp = fopen("xml/units/E01.xml","wb");
            fwrite($fp,$xml->asXML());
            fclose($fp);
        }
    }
}

Here is the xml:

<xml>
  <call>
     <wcccanumber>121202482</wcccanumber>
     <currentcall>FALL</currentcall>
     <county>W</county>
     <id>82</id>
     <location>234 E MAIN ST</location>
     <callcreated>12:26:09</callcreated>
     <station>HBM</station>
     <units>E01</units>
     <calltype>M</calltype>
     <lat>45.5225067888299</lat>
     <lng>-122.987112718574</lng>
     <inputtime>12/18/2012 12:27:01 pm</inputtime>
  </call>
</xml>
  • 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-16T04:51:30+00:00Added an answer on June 16, 2026 at 4:51 am

    Iterate through call and compare $call->wcccanumber with $wcccanumber. Convert $call to dom and remove it (parentNode->removeChild).

    foreach ($xml->call as $call) {
        if ($call->wcccanumber == $wcccanumber) {
            $dom = dom_import_simplexml($call);
            $dom->parentNode->removeChild($dom);
            $fp = fopen("xml/units/E01.xml","wb");
            fwrite($fp,$xml->asXML());
            fclose($fp);
        }
    }
    

    If there are multiple deletions it makes sense to save only once after all deletions have been done.

    $deletionCount = 0;
    
    foreach ($xml->call as $call) {
        if ($call->wcccanumber != $wcccanumber) {
            continue;
        }
        $dom = dom_import_simplexml($call);
        $dom->parentNode->removeChild($dom);
        $deletionCount++;
    }
    
    if ($deletionCount) {
        file_put_contents("xml/units/E01.xml", $xml->asXML());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to remove all child elements from a node but leave the actual
i am trying to remove parent tag, but removing parent tag should not remove
I am trying to remove an object from the parent environment. rm_obj <- function(obj){
I am trying to remove all script elements from a HTML page. But for
I am trying to remove unnecessary content from HTML. Specifically I want to remove
I'm trying to remove elements from webpages that aren't essential using querySelectorAll , but
I'm trying to remove a child entity from a parent collection navigation property. There
I am trying to remove a node from the dom tree using javascript while
I use this code: I'm trying to remove the categoryPath node but keep its
I'm trying to remove individual nodes from their parent, I tried the Remove method

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.