Link to home
Start Free TrialLog in
Avatar of JenebyM
JenebyM

asked on

Parsing an XML File

I need to get currency exchange rates from an RSS feed. I am having trouble (1) parsing the nodes and (2) getting the currency value.

I have successfully saved the xml file. The full file is attached :

The code section I am stuck with is:

 XmlNamespaceManager man = new XmlNamespaceManager(responseXML.NameTable);
                man.AddNamespace("rdf", "http://www.w3.org/1999/XSL/Transform");

                XmlNodeList xnList = responseXML.SelectNodes("rdf:RDF/item", man);
         
                foreach (XmlNode xn in xnList)
                {
                    if (xn["targetCurrency"].InnerText != "EUR")
                               //Get the value of the item :node"
                }

The xnList.Count = 0 which may indicate selectNodes list is not correct.

Please help

J
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  <channel rdf:about="http://xurrency.com/aud/feed">
    <title>Xurrency.com | AUD</title>
    <link>http://xurrency.com/aud/feed</link>
    <description>Australian Dollar</description>
    <dc:language>en-us</dc:language>
    <dc:rights>Creative Commons</dc:rights>
    <dc:date>2011-09-20T17:06:43Z</dc:date>
    <dc:creator>Xurrency.com</dc:creator>
    <dc:subject>Currency Values</dc:subject>
  </channel>
  <item rdf:about="http://xurrency.com/eur">
    <title xml:lang="en"><![CDATA[1 AUD = 0.7516 EUR]]></title>
    <link>http://xurrency.com/eur</link>
    <description xml:lang="en"><![CDATA[1 AUD = 0.7516 EUR]]></description>
    <dc:date>Tue Sep 20 18:03:00 UTC 2011</dc:date>
    <dc:language>en</dc:language>
    <dc:creator>Xurrency.com</dc:creator>
    <dc:simpleTitle>1 AUD = 0.7516 EUR</dc:simpleTitle>
    <dc:baseCurrency>AUD</dc:baseCurrency>
    <dc:targetCurrency>EUR</dc:targetCurrency>
    <dc:value frequency="daily" decimal="4">0.7516</dc:value>
  </item>
  <item rdf:about="http://xurrency.com/usd">
    <title xml:lang="en"><![CDATA[1 AUD = 1.0279 USD]]></title>
    <link>http://xurrency.com/usd</link>
    <description xml:lang="en"><![CDATA[1 AUD = 1.0279 USD]]></description>
    <dc:date>Tue Sep 20 18:03:00 UTC 2011</dc:date>
    <dc:language>en</dc:language>
    <dc:creator>Xurrency.com</dc:creator>
    <dc:simpleTitle>1 AUD = 1.0279 USD</dc:simpleTitle>
    <dc:baseCurrency>AUD</dc:baseCurrency>
    <dc:targetCurrency>USD</dc:targetCurrency>
    <dc:value frequency="daily" decimal="4">1.0279</dc:value>
  </item>


and so on

Open in new window

20110921-ExchangeRates.xml
ASKER CERTIFIED SOLUTION
Avatar of dimaj
dimaj
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JenebyM
JenebyM

ASKER

I need to identify what is wrong with parsing this specific file.

The node names appear peculiar and are not being parsed judging by the node.count = 0.

Using LINQ does not solve that problem and I will get nowhere by simply changing to using LInqXML if I cant get past this.

Please have a look at the XML file itself and see whether you can determine what Is the issue.

Many thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JenebyM

ASKER

Not really what I am looking for.

My problem is that i need to work with rdf and I was unable to read the xml file.

I have found what was missing:

1. I did not include all the required namespace reference for the RSS.
i.e
                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/");


2. The nodes list is obtained by:

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

These two changes have given me the results I need.

Will award partial marks for the answer.

Regards

Avatar of JenebyM

ASKER

research further and found solution I was looking for elsewhere
Glad you've got it resolved!

dimaj