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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:10:26+00:00 2026-05-11T12:10:26+00:00

All of the examples I can find online about this involve simply adding content

  • 0

All of the examples I can find online about this involve simply adding content to an XML file at the document root, but I really need to do it deeper than that.

My XML file is simple, I have:

<?xml v1 etc> <channel> <screenshots> <item>   <title>Image Title</title>   <link>www.link.com/image.jpg</link> </item> </screenshots> </channel> 

All I want to be able to do is add new ‘item’ elements, each with a title and link. I know I need to be using PHP DOM, but I’m stumped as to how to code it so that it adds data within ‘screenshots’ rather than overwriting the whole document. I have a suspicion I may need to use XPath too, but I have no idea how!

The code I have pieced together from online examples looks like this (but I’m certain it’s wrong)

$newshottitle = 'My new screenshot'; $newshotlink = 'http://www.image.com/image.jpg';  $dom = newDomDocument; $dom->formatOutput = true; $dom->load('../xml/screenshots.xml');  $dom->getElementsByTagName('screenshots'); $t = $dom->createElement('item'); $t = $dom->createElement('title'); $t->appendChild($dom->createTextNode('$newshottitle'));  $l = $dom->createElement('link'); $l->appendChild($dom->createTextNode('$newshotlink'));  $dom->save('../xml/screenshots.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. 2026-05-11T12:10:26+00:00Added an answer on May 11, 2026 at 12:10 pm

    adding content to an XML file at the document root, but I really need to do it deeper than that.

    You’re not adding content anywhere at the moment! You create <title> and <link> element nodes with text in, then you do nothing with them. You should be passing them into ‘appendChild’ on the <item> element node (which also you are currently creating and immediately throwing away by not assigning it to a variable).

    Here’s a starting-point:

    $screenshots= $dom->getElementsByTagName('screenshots')[0];  $title= $dom->createElement('title'); $title->appendChild($dom->createTextNode($newshottitle)); $item= $dom->createElement('item'); $item->appendChild($title); $screenshots->appendChild($item); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All the examples that I can search online use the App.Config mode of specifying
Following this example, I can list all elements into a pdf file import pyPdf
Can source code examples be kept in a SQL database while retaining all formatting
Inspired by this question I began wondering why the following examples are all illegal
How can one remove all text, but leave the structure intact? for example: <animals>
All the examples I see are for Java SE applications by passing your JAR
After freezing edge rails, all my controller examples are failing with MissingTemplate errors. e.g.,
Example: find / * Gives me all files and directories, but I want only
If all tables I want to delete from have the column gamer_id can i
For example, here on stack overflow the URL https://stackoverflow.com/questions/tagged/javascript+php will give you all questions

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.