Jquery:从xml中删除特定节点并获取剩余的xml

Below is my xml, I want to remove complete data including <onward-solutions> from the below xml.

var xml=' 
   <search-result>
   <onward-solutions>
    <solution index="1">
    </solution>
    <solution index="2">
    </solution>
    <solution index="3">
    </solution>
    </onward-solutions>
    <return-solutions>
    <solution index="1">
    </solution>
    <solution index="2">
    </solution>
    <solution index="3">
    </solution>
    </return-solutions>
    </search-result>
';

Below is the estimated output from xml:

<search-result>
<return-solutions>
<solution index="1">
</solution>
<solution index="2">
</solution>
<solution index="3">
</solution>
</return-solutions>
</search-result>

Can any one help me how to get the expected result?

If you want to use jQuery, you could try the following:

// Convert the xml string to a jQuery object.
var $xml = $(xml);

// Manipulate the jQuery object.
$xml.children('onward-solutions').remove();

// Convert the jQuery object back to an xml string.
xml = $xml.wrap('<x></x>').parent().html();

jsfiddle

If your xml string contains an xml declaration at the beginning, like this:

<!--?xml version="1.0" encoding="UTF-8"?-->

You can use the following:

// Parse the xml string into an XMLDocument and then create a jQuery object
// using the root element.
var $xml = $($.parseXML(xml).documentElement);

//  Manipulate the jQuery object.
$xml.children('onward-solutions').remove();

// Convert the jQuery object back to an xml string.
// Note: For some reason the .wrap() function does not work in this case,
//       so we use .appendTo() instead.
xml = $xml.appendTo('<x></x>').parent().html();

jsfiddle