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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:44:41+00:00 2026-05-18T04:44:41+00:00

<root> <gallery name=First/> <gallery name=Second/> <gallery name=Third/> </root> I think I have solved part

  • 0
<root>
  <gallery name="First"/>
  <gallery name="Second"/>
  <gallery name="Third"/>
</root>

I think I have solved part of a previous problem and now have the foreach loop correct? Still I can’t get it to save the xml.

$objXML = new SimpleXMLElement(XML_FILE_NAME, null, true);  
foreach($objXML->xpath('/root/gallery/@name') as $key => $old){
    $new = $_POST['name'][$key];
    echo "$key : $old : $new<br />\n";
    $old = $new; // this does nothing??
    }
$objXML->asXML(XML_FILE_NAME);

echo returns:
0 : First : First New
1 : Second : Second New
2 : Third : Third New

Why does this not save the new posted values for ‘name’ back to my XML doc, what am I doing wrong?

  • 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-18T04:44:41+00:00Added an answer on May 18, 2026 at 4:44 am

    You’re in a loop.

    This mean each time the loop comes back to another point $key and $old get their respective new values.

    I guess that’s what you’re trying to achieve (but I’m not you’re sure I got your goal here)

    foreach($objXML->xpath('/root/gallery/@name') as $key => $value){
        $new = $_POST['name'][$key];
        echo "$key : $old : $new<br />\n";
        $old = $value;
    }
    

    From your comment :

    You can test it here.

    $objXML = new SimpleXMLElement(XML_FILE_NAME, null, true);  
    
    $galleryLore = $objXML->gallery; // finding gallery
    $i = 0;
    foreach($galleryLore as $gallery){
      unset($gallery['name']); // We delete the old name
      $new = $_POST['name'][$i]; // We find the new name value
      $gallery->addAttribute('name', $new); // We add the new attribute we deleted before
      $i++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<root> <gallery name=First/> <gallery name=Second/> <gallery name=Third/> </root> I'm trying to rename multiple name
How can I achieve this: <root> <gallery name=First> <picture active=1 detail=not shown/> <picture active=1
I have the following tree: root -js_src -php_src -images Now, how do i reliably
I have a library which has root package scala, and now I have a
Currently I have a root-level repository set up for each project, like so: Project1
I have a text file in the root of my web app http://localhost/foo.txt and
We have a Java program run as root on Unix, that therefore can read
i have a url like this http://example.com/blog/photos/photos/gallery/image/1 . And i need to remove the
I have set the password for root and grant all privileges for root. Why
I'd like to make a gallery of all images i have under my domain

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.