Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing XML data into RichTextBox but Only One Item Appeared in Result
    primarykey
    data
    text
    <p>I am working on my project, I am totally new to C# and I need to use C# to do my work. I really hope you guys can lend me a hand in the below issue. Your help will be very much appreciated!! Thanks.</p> <p>I have an XML file which has two <code>&lt;item&gt;...&lt;/item&gt;</code> in parent <code>&lt;channel&gt;</code>. I executed my code, what I get is only as below - data of one <code>&lt;item&gt;</code> appeared:</p> <blockquote> <p>Title: Re: My view of Tesco</p> <p>Desciption: Stay clear of the iii IPO when it comes onto the market. 3 quarters are multiples, triples, quadrupole, W-T-F. It´s like ebay a lot bidding there, is fake too.</p> <p>Today´s thought of the day: Odd is that Deloitte seems to have escaped headlines. Accusation it colluded with Standard Chartered on regulatory report cd be Enron moment Remember those old accountants Deloitte, Mr. Hyman (RBS)? By Hardcore Uproar </p> <p>Date: Tue, 07 Aug 2012 14:03:00 GMT</p> <h2>Author: Hardcore Uproar</h2> </blockquote> <p>My code is as below:</p> <pre><code> private void btnComSearch_Click(object sender, EventArgs e) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("tsco.xml"); XmlElement root = xmlDoc.DocumentElement; XmlNodeList nodes = root.SelectNodes("item"); foreach (XmlNode node in nodes) { XmlNodeList comTitle = xmlDoc.GetElementsByTagName("title"); XmlNodeList comDesc = xmlDoc.GetElementsByTagName("description"); XmlNodeList comDate = xmlDoc.GetElementsByTagName("pubDate"); XmlNodeList comAuthor = xmlDoc.GetElementsByTagName("creator"); StringBuilder sb = new StringBuilder(); sb.AppendLine("Title: " + comTitle[0].InnerText + "\n"); sb.AppendLine("Desciption: " + comDesc[0].InnerText + "\n"); sb.AppendLine("Date: " + comDate[0].InnerText + "\n"); sb.AppendLine("Author: " + comAuthor[0].InnerText + "\n" + "---------------" + "\n"); richComResults.Text = sb.ToString(); } } </code></pre> <p>My XML file:</p> <pre><code>&lt;channel&gt; &lt;item&gt; &lt;title&gt;Re: My view of Tesco&lt;/title&gt; &lt;description&gt; &lt;![CDATA[ Stay clear of the iii IPO when it comes onto the market. 3 quarters are multiples, triples, quadrupole, W-T-F. It´s like ebay a lot bidding there, is fake too.Today´s thought of the day: Odd is that Deloitte seems to have escaped headlines. Accusation it colluded with Standard Chartered on regulatory report cd be Enron moment Remember those old accountants Deloitte, Mr. Hyman (RBS)? By Hardcore Uproar ]]&gt; &lt;/description&gt; &lt;pubDate&gt;Tue, 07 Aug 2012 14:03:00 GMT&lt;/pubDate&gt; &lt;creator&gt;Hardcore Uproar&lt;/creator&gt; &lt;/item&gt; &lt;item&gt; &lt;title&gt;&lt;/title&gt; &lt;description&gt; &lt;![CDATA[ Raw material inflation; Rising (relative) wealth outside of EU. Increased global demand for agri-commodities due to increasing population and relative wealth of Eastern countries. Decoupling of subsidy from agri-production = bad for supermarkets. Weather problems, diminished /(ing) resources and a general plateau reached in agriculture in terms of yield achievable = limited supply. Over supply of supermarkets/ retailers (too much choice= supply&gt;demand) Diminished disposable income; General recession. Poor pension performance. Over indebtidness in UK (further compounded by any increases in interest rates required to curb inflation). All this is bad news for supermarkets.. in my locality in a farily small town of 14,000 people we have a large ASDA, huge TESCO and M and S and numerous discounters.. they must be counting on all 14000 of those people visiting ALL of their local supermarkets at least 9 times a week IMHO!! By t8vet ]]&gt; &lt;/description&gt; &lt;pubDate&gt;Mon, 06 Aug 2012 18:47:00 GMT&lt;/pubDate&gt; &lt;creator&gt;t8vet&lt;/creator&gt; &lt;/item&gt; &lt;/channel&gt; </code></pre> <p>My Edited Code after applying your (horgh) codes:</p> <pre><code>private void btnComSearch_Click(object sender, EventArgs e) { XmlDocument xmlDoc = new XmlDocument(); //* create an xml document object. xmlDoc.Load("tsco.xml"); //* load the XML document from the specified file. XmlElement root = xmlDoc.DocumentElement; XmlNodeList nodes = root.SelectNodes("item"); // You can also use XPath here foreach (XmlNode node in nodes) { StringBuilder sb = new StringBuilder(); foreach (XmlNode child in node.ChildNodes) sb.AppendLine(string.Format("{0}:\t{1}", child.Name, child.FirstChild == null ? string.Empty : child.FirstChild.Value)); richComResults.Text = sb.ToString(); } Console.ReadLine(); } </code></pre> <p>I am totally lost. I tried looking through the websites and also those were asking similar questions, but I don't really understand and I tried they don't work in my situation. I am not sure what have I done wrongly. Your help would be much appreciated :) Thank you so much.</p>
    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.
 

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