Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trouble Parsing XML nodes

Posted on 2011-09-20
3
Medium Priority
?
359 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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.
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. 
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…
Suggested Courses

926 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