Solved

Trouble Parsing XML nodes

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

777 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