txtComKeyword1
XMLファイルを検索して、これらのテキストボックス、、、および/またはtxtComKeyword2
に挿入された単語に一致するコンテンツがあるかどうかを確認しています。以下の機能は機能していますが、リッチテキストボックスに表示される一致する4つのテキストボックスにユーザーが入力したキーワードを強調表示するにはどうすればよいですか?txtComKeyword3
txtComKeyword4
richComResults
たとえば、私のユーザーはこれらの4つのテキストボックスに入力します。txtComKeyword1、txtComKeyword2、txtComKeyword3およびtxtComKeyword4。次に、コードはXMLファイルを解析して、ノードにこれらの4つのキーワードが含まれているかどうかを確認します。含まれている場合は、ノードのデータがrichComResultsに出力されます。これらの4つのキーワードを強調表示します(例:txtComKeyword1 = hello、txtComKeyword2 = bye、txtComKeyword3 =朝、txtComKeyword4 =夜)。これらの4つの単語が見つかり、richComResultsに表示されると、色で強調表示されます。
しばらく検索した後、私には手がかりがありません。私の場合は他の質問とは大きく異なります。私はプログラミングの初心者です。あなたの助けをいただければ幸いです。ありがとうございました!
私のコード:
private void searchComByKeywords()
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(sourceDir);
foreach (string fileName in fileEntries)
{
XmlDocument xmlDoc = new XmlDocument(); //* create an xml document object.
string docPath = fileName;
xmlDoc.Load(docPath); //* load the XML document from the specified file.
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("item");
foreach (XmlNode node in nodeList)
{
XmlElement itemElement = (XmlElement) node;
string itemDescription = itemElement.GetElementsByTagName("description")[0].InnerText;
if (txtComKeyword1.Text != (String.Empty) && itemDescription.ToLower().Contains(txtComKeyword1.Text.ToLower()) ||
txtComKeyword2.Text != (String.Empty) && itemDescription.ToLower().Contains(txtComKeyword2.Text.ToString()) ||
txtComKeyword3.Text != (String.Empty) && itemDescription.ToLower().Contains(txtComKeyword3.Text.ToString()) ||
txtComKeyword4.Text != (String.Empty) && itemDescription.ToLower().Contains(txtComKeyword4.Text.ToString()))
{
string itemTitle = itemElement.GetElementsByTagName("title")[0].InnerText;
string itemDate = itemElement.GetElementsByTagName("pubDate")[0].InnerText;
string itemAuthor = itemElement.GetElementsByTagName("author")[0].InnerText;
richComResults.AppendText("Author: " + itemAuthor + "\nDate: " + itemDate + "\nTitle: " + itemTitle + "\nDescription: " + itemDescription + "\n\n--------\n\n");
}
}
}
}