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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:02:45+00:00 2026-05-18T07:02:45+00:00

I want to delete some nodes or add some nodes in xml with jquery,

  • 0

I want to delete some nodes or add some nodes in xml with jquery,
I try it with append, empty, remove but all of them seem to not work,
like (in $.ajax):

success:function(xml){
    $(xml).find("layout").append('<app id="' + $children.eq(i).attr("id") + '"></app>');
    $(xml).find("layout").empty();
}

also I find there is no tutorial on google.
So I wonder is it possible add or delete nodes in xml with jquery?

OK ,I write it in details,the xml file just save in local domain as Database/UserConfig/config.xml
here is my Ajax code:

function layout_change()
{
    var $children=$input.children();

    $.ajax({
        type: "get",
        url: "Database/UserConfig/config.xml",
        dataType: "xml",
        timeout: 2000,
        beforesend:function(xml){
            $(xml).find("layout").empty();
        },
        success:function(xml){
            for(var i=0;i<$children.length;i++)
            {
                $(xml).find("layout").append('<app id="' + $children.eq(i).attr("id") + '"></app>');              
            }
        },
        error:function(){}
    });
}

or it can be done with javascript?or can be only done with server language like C#?……

here is my demo xml:

<layout>
        <app id="id-4"></app>
        <app id="id-5"></app>
        <app id="id-6"></app>
        <app id="id-1"></app>
        <app id="id-2"></app>
        <app id="id-3"></app>   
</layout>
  • 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-18T07:02:45+00:00Added an answer on May 18, 2026 at 7:02 am

    jQuery is a fantastic tool for parsing and manipulating XML in javascript. jQuery’s ajax APIs were, in fact, built with this in mind which is why you’re able to specify the response type of an ajax call by setting the dataType argument to xml (although they do try to do some auto-detection if this argument is omitted). From the jQuery $.ajax() documentation for the dataType argument:

    “xml”: Returns a XML document that can
    be processed via jQuery.

    You can parse and manipulate XML as much as want using jQuery. I’ll have to add that using CSS selectors is wonderful compared to XPath queries in server-side XML libraries.

    While empty and remove work as expected, there’s a gotcha when adding nodes on the fly with functions like append: jQuery, for whatever reason (I haven’t really dug into this), won’t create the element for you when appending to the XML structure (although this works fine in HTML structures). You can get around this easily by explicitly creating the node yourself as a DOM element or jQuery object and then calling append:

    //Either of these will work
    var elem = document.createElement('app');
    xml.find('layout').append(elem); // Appends <app></app> to <layout>
    xml.find('layout').append($('<app>')); // Does the same
    
    // You can also you use other manipulation functions such as `attr`
    xml.find('layout').append($('<app>').attr('id', 'ego'));
    

    It looks like, however, that there are other problems with your code that would be preventing it from behaving as expected. The $.ajax beforeSend callback, for example, passes in the XMLHttpRequest object to the callback function and not your XML object to be manipulated. The result is that your empty call in that callback does nothing.

    Also, if you’re trying to manipulate the response of Database/UserConfig/config.xml in the beforeSend callback, it probably won’t have existed yet since beforeSend is called before the ajax request is fired off. It’s possible that the xml argument you intended to pass in was scoped globally, but it’s squashed in the scope of the callback since jQuery is passing in XMLHttpRequest as I mentioned before.

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

Sidebar

Related Questions

I want to perform cascade delete for some tables in my database, but I'm
I want to delete all but the 4 newest directories in my parent directory.
I'm writing an application in PHP 5. I want to delete some rows in
I want to delete all directories and subdirectories under a root directory that are
I have a grid layout with image nodes and I want to add in
I want to delete some data use: $dbc=mysql_connect(_SRV,_ACCID,_PWD) or die(_ERROR15.: .mysql_error()); $db=mysql_select_db(qdbase,$dbc) or die(_ERROR17.:
Delete some specific data present in a file.What ever user want to delete that
Hey guys i wrote a quick test. I want delete to call deleteMe which
I want to delete foo() if foo() isn't called from anywhere.
I want to delete a folder that contains thousands of files and folders. If

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.