我有下面的代码。<item></item>
假设用户可以插入1-4个关键词并点击搜索按钮,那么如果子标签中的内容<description</description>
包含一个/多个输入的关键词,就会有结果在richtextbox中显示出来。但是代码在这一行不正确if (itemDescription.Contains(txtComKeyword1 | txtComKeyword2 | txtComKeyword3 | txtComKeyword4)
。
请问大家可以看一下吗?非常感谢您的帮助!谢谢你。
以下是我的 XML 文件结构的一部分:
<item>
<title>[PhoTosynthesIs] Being driven</title>
<author>PhoTosynthesIs</author>
<description>purely by profit, I've decided to stick to my strategy and exit both tranches at 177. Will pick this stock up again when it breaches and holds the next pivot point. gl all</description>
<link>http://www.lse.co.uk/shareChat.asp?ShareTicker=BARC&post=5660817</link>
<pubDate>Wed, 08 Aug 2012 11:43:17 GMT</pubDate>
</item>
<item>
<title>[b36m] alw51</title>
<author>b36m</author>
<description>Could you share your thoughts/opinions on a buy in price based on TW with me please many thanks</description>
<link>http://www.lse.co.uk/shareChat.asp?ShareTicker=BARC&post=5660636</link>
<pubDate>Wed, 08 Aug 2012 11:16:56 GMT</pubDate>
</item>
下面是我的这个函数的一段代码:
private void searchComByKeywords()
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(sourceDir);
foreach (string fileName in fileEntries)
{
try
{
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 (itemDescription.Contains(txtComKeyword1 | txtComKeyword2 | txtComKeyword3 | txtComKeyword4)
{
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");
}
//else
//{
// richComResults.AppendText("There is no author " + txtComAuthor.Text.ToString().ToLower() + ". Please ensure you are using a correct author name.");
//}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}