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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:01:51+00:00 2026-05-19T03:01:51+00:00

I would like to add an element node in my XML file using PHP.

  • 0

I would like to add an element node in my XML file using PHP. I can not get it right when I add it below root.
Please show me some clean code so that I understand how it works. Thank you!
My xml is

<?xml version="1.0" encoding="utf-8"?>
<GameStore>

    <Game type="adventure">
    <TITLE>Assassin's Creed: Brotherhood</TITLE>
    <PUBLISHER>Ubisoft</PUBLISHER>
    </Game> 

    <Game type="adventure">
    <TITLE>Batman: Arkham Asylum</TITLE>
    <PUBLISHER>Eidos</PUBLISHER>
    </Game>

    </GameStore>
  • 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-05-19T03:01:52+00:00Added an answer on May 19, 2026 at 3:01 am

    If you want to add a new game element, simplexml handles this pretty convenient. Example ($data is obviously your xml):

    $xml = simplexml_load_string($data);
    $game = $xml->addChild("game");
    $game->addAttribute("type", "Game type");
    $game->addChild("title", "Game title");
    $game->addChild("publisher", "Game publisher");
    
    echo $xml->saveXML();
    

    This will append a “game” child to your xml. We then append two children (title, publisher) to game.

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

Sidebar

Related Questions

I am with an array like $x = array(1,2,3,4,5); i would like to add
I would like to add the id attribute to a label field in a
I am trying to implement LRU Cache using C++ . I would like to
How would the conditional statement look like if I'm to insert a section of
I would like to put a GSList inside a GHashTable , here is how
In the example code below, I have a question about the List. My prof
I created a method and pass the element type, id, and any inner text
I needed some method of adding/removing classes of a parent element when it's children
I have a number of vector containers of varying size each containing doubles. I
I am having a little bit trouble with the following. I have multiple form

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.