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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:37:54+00:00 2026-06-04T02:37:54+00:00

I have a website here that writes info to and XML file, here is

  • 0

I have a website here that writes info to and XML file, here is my code:

<?php
$doc = new DOMDocument();
$doc->load("xml/latestContent.xml");
$rootElement = $doc->documentElement;

// Create latestpic element as a child of the root element
$latestPicElement = $rootElement->appendChild($doc->createElement("latestpic"));
$latestPicElement->appendChild($doc->createElement("item", "Latest Pic"));
$latestPicElement->appendChild($doc->createElement("content", $latestPic));

// Create latestvideo element as a child of the root element
$latestVidElement = $rootElement->appendChild($doc->createElement("latestvideo"));
$latestVidElement->appendChild($doc->createElement("item", "Latest Video"));
$latestVidElement->appendChild($doc->createElement("content", $videoData));

// Create latestfact element as a child of the root element
$latestFactElement = $rootElement->appendChild($doc->createElement("latestfact"));
$latestFactElement->appendChild($doc->createElement("item", "Latest Fact"));
$latestFactElement->appendChild($doc->createElement("content", $factData));

// Save back to XML file
$doc->save("xml/latestContent.xml");
?>

The problem here is every time I load the webpage it reloads this function which just adds the same data back onto the XML file, I would like it to replace the original data if I can? How do I go about doing this? I have researched the replaceChild method but can not get the syntax quite right. Can anyone please show me?

Or is there a way I can add in there to load a blank xml every time? So it just adds the content to a new XML file?

Thanks so much in advance!

  • 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-04T02:37:56+00:00Added an answer on June 4, 2026 at 2:37 am

    You need a pointer to the node you’re trying to replace if you want to use replaceChild(). On the other hand, if the idea is to replace all of the data, why read the existing file?

    //$doc->load("xml/latestContent.xml"); not needed
    $rootElement = $dom->appendChild($doc->createElement("Root"));
    

    This new document will overwrite the previous one. You can get more info here.

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

Sidebar

Related Questions

I need some things clarified here: I have a website that updates the values
here is my scenario: I have a website with php, mySQL. I have a
I have set up a website here: http://liamwli.co.uk/ggsim On the bottom, there are 2
I work for a travel agency, they have a website, from here they want
Here's what I am working on. At my website I have multiple processes with
Right, here's the story: We have had a website for one of our brands
ASP.NET newbie here I have coded up an ASP.NET website and running on win'08
So here is my problem: I have coded an administration area for my website,
Here's another one for you to help me solve: I have an ASP.NET website
Okay, so here's my problem: I have a list of members on a website,

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.