Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing Through XML Files with Selected Keywords
    primarykey
    data
    text
    <p>I have the below code. Supposed, a user can insert 1-4 keywords and click search button, then there will be results showing the whole <code>&lt;item&gt;&lt;/item&gt;</code> in the richtextbox if the content in sub-tag <code>&lt;description&lt;/description&gt;</code> contain one/more of the keywords entered. But the code is not right at this line <code>if (itemDescription.Contains(txtComKeyword1 | txtComKeyword2 | txtComKeyword3 | txtComKeyword4)</code>.</p> <p>Please could you guys take a look at it? Your help is much appreciated! Thank you.</p> <p>The below is part of my XML file structure:</p> <pre><code>&lt;item&gt; &lt;title&gt;[PhoTosynthesIs] Being driven&lt;/title&gt; &lt;author&gt;PhoTosynthesIs&lt;/author&gt; &lt;description&gt;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&lt;/description&gt; &lt;link&gt;http://www.lse.co.uk/shareChat.asp?ShareTicker=BARC&amp;amp;post=5660817&lt;/link&gt; &lt;pubDate&gt;Wed, 08 Aug 2012 11:43:17 GMT&lt;/pubDate&gt; &lt;/item&gt; &lt;item&gt; &lt;title&gt;[b36m] alw51&lt;/title&gt; &lt;author&gt;b36m&lt;/author&gt; &lt;description&gt;Could you share your thoughts/opinions on a buy in price based on TW with me please many thanks&lt;/description&gt; &lt;link&gt;http://www.lse.co.uk/shareChat.asp?ShareTicker=BARC&amp;amp;post=5660636&lt;/link&gt; &lt;pubDate&gt;Wed, 08 Aug 2012 11:16:56 GMT&lt;/pubDate&gt; &lt;/item&gt; </code></pre> <p>The below is my piece of code for this function:</p> <pre><code>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); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload