Solved

Trouble Parsing XML nodes

Posted on 2011-09-20
3
348 Views
Last Modified: 2013-11-18
I have an XML document loaded from an RSS feed and I want to pick the exchange rate value shown in the dc:value node.

The value should simply be displayed in  Label1.text.

I have been able to read all 23 items from the "item" node but can't seem to get the value from the child nodes. Anyone able to see the problem with this code and the fix for it. I attach the xml document as well.

Please help!
man.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
                man.AddNamespace("slash", "http://purl.org/rss/1.0/modules/slash/");
                man.AddNamespace("taxo", "http://purl.org/rss/1.0/modules/taxonomy/");
                man.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
                man.AddNamespace("syn", "http://purl.org/rss/1.0/modules/syndication/");
                man.AddNamespace("admin", "http://webns.net/mvcb/");
                man.AddNamespace("feedburner", "http://rssnamespace.org/feedburner/ext/1.0");
                man.AddNamespace("rss", "http://purl.org/rss/1.0/");

                XmlNodeList xnList = responseXML.SelectNodes("rdf:RDF//rss:item", man);

                bool found = false;
                foreach (XmlNode xn in xnList)
                {
                    XmlNode currencyCODE = xn.SelectSingleNode("descendant::dc:baseCurrency", man);
                    found = (currencyCODE != null) ? true : false;
                    if (found)
                    {
                        if (currencyCODE.InnerText == "AUD")
                        {
                            XmlNode currencyVALUE = xn.SelectSingleNode("descendant::dc:value", man);
                            if (currencyVALUE != null)
                                Label1.Text = currencyVALUE.InnerText;
                        }
                        break;
                    }
                }

Open in new window

201109211103-ExchangeRates.xml
0
Comment
Question by:JenebyM
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 36571662
you need to add a namespace

xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.2/"

                man.AddNamespace("cb", "http://www.cbwiki.net/wiki/index.php/Specification_1.2/");

both value and baseCurrency are NOT in dc: but in cb:
0
 

Author Comment

by:JenebyM
ID: 36571913
Perfect:


0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36571916
welcome
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now