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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:46:24+00:00 2026-05-19T04:46:24+00:00

This may be a simple question though can´t figure out how to do it.

  • 0

This may be a simple question though can´t figure out how to do it.
I want to load and modify an xml file, then save the xml through php.

Here is the code:

 $.ajax({
  type: "GET",
  url: "menu.xml",
  dataType: "xml",
  success: function(xml) {
   $(xml).find('menu_item').each(function(){
    //change the value of menu_item
    $(this).empty();
    $(this).text($("textarea").attr("value"));
    //send xml to php
    $.post('save_xml.php', $(xml), function(data){alert("Data Loaded: " + data);});
   }

  }
 });

Here is how save_xml.php looks like:

<?php

    $xml = $GLOBALS["HTTP_RAW_POST_DATA"];
    $file = fopen("file.xml","w");
    fwrite($file, $xml);
    fclose($file);
    echo "ok";

?> 
  • 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-19T04:46:24+00:00Added an answer on May 19, 2026 at 4:46 am

    Is this what you are looking for?

    $(this) is each of the menu_items you iterate over with .each()

    Your code becomes

    $(xml).find('menu_item').each(function(){
       $(this).text("New Value");
    });
    

    Hope this helps

    EDIT

    To post this back to the server I would do this:

    $.post('save_xml.php', { xml: $(xml)}, function(data){alert("Data Loaded: " + data);});
    

    and then in the PHP file

    <?php
      $xml = $_POST['xml'];
      $file = fopen("file.xml","w");
      fwrite($file, $xml);
      fclose($file);
      echo "ok";
    ?> 
    

    This code is untested, and there could be any number of reasons it doesn’t work, write permissions on the files etc.

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

Sidebar

Related Questions

This may be a painfully simply question for which I will be mocked but
This may be simple one, but 5 mins of Googling didn't give me the
This may be a simple fix - but I'm trying to sum together all
This may be a very simple problem, but I couldn't find an answer googleing
This may seem like a daft question, but i was wondering about how to
This may seem like a programming 101 question and I had thought I knew
I'm trying to figure out two things: Can Xpath be used to query a
I think this is a very simple question, but I’m new to programming so
Simple question: In Visual Studio, how can I see whether an assembly is referenced
This may be a no-brainer for the WPF cognoscenti, but I'd like to know

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.