Solved

Trouble Parsing XML nodes

Posted on 2011-09-20
3
351 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 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

19 Experts available now in Live!

Get 1:1 Help Now