php - Jquery: remove the particular node from xml and get remaining xml -


below xml, want remove complete data including <onward-solutions> 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 estimated output xml:

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

can 1 me how expected result?

if want use jquery, try following:

// convert xml string jquery object. var $xml = $(xml);  // manipulate jquery object. $xml.children('onward-solutions').remove();  // convert jquery object xml string. xml = $xml.wrap('<x></x>').parent().html(); 

jsfiddle

if xml string contains xml declaration @ beginning, this:

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

you can use following:

// parse xml string xmldocument , create jquery object // using root element. var $xml = $($.parsexml(xml).documentelement);  //  manipulate jquery object. $xml.children('onward-solutions').remove();  // convert jquery object xml string. // note: reason .wrap() function not work in case, //       use .appendto() instead. xml = $xml.appendto('<x></x>').parent().html(); 

jsfiddle


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -