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 simple question though can´t figure out how to do it.
This may be a simple question for you experts but I can't figure out
This may be a simple question, but I can't figure out a simple way
This may be very simple question,But please help me. i wanted to know what
Okay this may be a simple question but I have yet to come with
This may seem like a simple question but i am getting an error when
this may be a very simple question, but is it possible to force a
This may seem a very silly question. Consider this: I have a simple Boolean
may be too simple groovy question but....please help i have a list like this:
This may be a really simple question, but I'm trying to create the database

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.