Q:

How to check if XML string contains certain value in jQuery

I would like to use Ajax to check if an XML string ("data") contains a certain value under "voteBy", e.g. the name "John Doe". If yes, then I want to show an alert, if not then show another alert. The idea behind is that I want to do something here later with jQuery but only if the search term is NOT found in the XML string.
I tried the below which is the success function of the Ajax call to fetch this XML string. In this case it should alert "found" as the search term appears in the XML string but my approach doesn't return anything.
Can someone tell me what I am doing wrong here? Note: Data for the XML can vary so there may be more or less or no votes for a certain item.
My XML looks as follows (example data, shortened): 
<ranks>
  <itemDetails>
    <itemID>1</itemID>
    <title>Test item</title>
    <details>&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit...&lt;/p&gt;</details>
    <lastUpdate>Added</lastUpdate>
    <modTime>Saturday, 23 August 2014</modTime>
    <modBy>Someone</modBy>
    <comments>
      <commentID>1</commentID>
      <comment>Some comment</comment>
    </comments>
    <comments>
      <commentID>2</commentID>
      <comment>Another comment</comment>
    </comments>
    <votes>
      <voteBy>John Doe</voteBy>
    </votes>
    <votes>
      <voteBy>Jane Doe</voteBy>
    </votes>
  </itemDetails>
</ranks>

My jQuery (success function only, shortened) - data here is my XML string:
$.ajax({
    // ...
    success:function(data) {    
        if(!$(data).find('voteBy').text() == 'John Doe') {
            alert('not found');
        } else {
            alert('found');
        }
    }
});

A:

one way is using .each element for xml nodes : 
var yourXML;     
function search_xml(string_for_search){
  $.ajax({
     type:"GET",
     url: "xml_file.xml",
     dataType: "xml",
     success: function(xml){

          $(xml).find('voteBy').each(function(){
          if($(this).text() == string_for_search) alert ('found :)');
          else alert ('not found ! :(');
          });

        }
  });
}

search_xml("John Does");

another way : using .filter and .find 
var yourXML;     
function search_xml(string_for_search){
  $.ajax({
     type:"GET",
     url: "xml_file.xml",
     dataType: "xml",
     success: function(xml){
              // Filter 
            myXML = $(xml).find("itemDetails").filter(function() {
                return $(this).find('voteBy').text() == string_for_search;
            });

             // Store a string with your keywords 
            var output = myXML.children().map(function() {
                return this.tagName + '=' + $(this).text();
            }).get().join(' ');

            alert(output);
        }
  });
}

search_xml("John Doe");

