/// <summary> /// Compare the titles of the albums returned by Amazon with the current Album /// from the DB. Return the best match if it meets the threshold. /// </summary> /// <param name="items"></param> /// <param name="theAlbum"></param> /// <param name="nsmgr"></param> /// <returns>Return </returns> private XmlNode CheckTitles(XmlNodeList items, Album theAlbum, XmlNamespaceManager nsmgr) { // start off with a really high number, the only way is down int lowestScore = 1000; XmlNode lowestItem = null; // work through each node foreach (XmlNode item in items) { // extract the title of this item XmlNode amazonTitle = item.SelectSingleNode("amazon:ItemAttributes/amazon:Title", nsmgr); string amazonTitleString = PrepareString(amazonTitle.InnerText); string albumTitle = PrepareString(theAlbum.Title); // calculate the distance between this and the actual album int distance = LevenshteinDistance.CalculateDistance(amazonTitleString, albumTitle); // store the reference if this is the best match if (distance < lowestScore) { lowestItem = item; lowestScore = distance; } } // send back the best match if it meets the threshold if (lowestScore < AmazonConstants.LEVENSHTEIN_THRESHOLD) { return(lowestItem); } return(null); }