xml - Javascript search for string match and display no duplicates -


here's xml

<document>     <item>     <my_summary>the cow jump on moon</my_summary>     </item>     <item>     <my_summary>pepper piper keeper moon</my_summary>     </item>     <item>     <my_summary>the swan flew jump lake</my_summary>     </item>     <item>     <my_summary>moon stars blue yellow</my_summary>     </item>     </document> 

here's javascript loop code

var count_my_summary =xmldoc.getelementsbytagname("item"); var keywords = "over moon"; var filtered_array_exclude = keywords.match(/\w+/g).map(function(i) {return i.tolowercase();}).filter(function(i) { return exclusionlist.indexof(i) == -1; })  var filtered_array = new removeduplicateelement(filtered_array_exclude);   (xml_i=0;xml_i<count_my_summary.length;xml_i++){       (var = 0; < filtered_array.length; i++) {         var xml_summary_lowercase = count_my_summary[xml_i].getelementsbytagname("my_summary")[0].childnodes[0].nodevalue.tolowercase();         var result = xml_summary_lowercase.indexof(keyword,0);         if (result > -1) {         document.write(my_summary + "<br><br>");         } else {         document.write("");         }     }      } } 

the result of code loop my_summary , display when there's match. there's duplication of result, because "over" or "moon"

the cow jump on moon - "over" match cow jump on moon - "moon" match pepper piper keeper moon - "moon" match moon stars blue yellow - "moon" match 

my target result remove duplicates... example remove "the cow jump on moon"

the cow jump on moon - "over " , "moon" match pepper piper keeper moon - "moon" match moon stars blue yellow - "moon" match 

how can make search "over" , "moon" , if there's match, don't display duplicate.

i have done differently. use jquery elements need can output them you'd like. filter function checks each element match filter words. way wont have duplicates since iterates each element once (internally maybe more due loop)

var filterstring = "moon over"; var filterarr = filterstring.split(" ");  $(xmldoc).find("my_summary").filter(function(){ for(var str in filterarr){ if ($(this).text().search(str) > -1) return true; } return false; }); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -