0

I have this simple XML document from a webservice

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"    xmlns="http://purl.org/rss/1.0/" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3c.org/1999/02/22-rdf-syntax-ns#rdf.xsd">
<channel rdf:about="http://www.bankofcanada.ca/stats/">
<title xml:lang="en">Bank of Canada closing rate: U.S. dollar (close)</title> 
<link>www.bankofcanada.ca/</link> 
<description>Current day's closing foreign exchange rates from the Bank of Canada. Published at  about 4:15 ET.</description> 
 <items>
  <rdf:Seq>
   <rdf:li rdf:resource="http://www.bankofcanada.ca/stats/assets/rates_rss/STATIC_IEXE0102.xml" /> 
  </rdf:Seq>
 </items>
</channel>
<item rdf:about="http://www.bankofcanada.ca/stats/rates_rss/STATIC_IEXE0102.xml">
 <title xml:lang="en">CA: 1.0378 USD = 1 CAD 2011-05-09 Bank of Canada closing rate</title> 
 <link>http://www.bankofcanada.ca/rates/exchange/daily-closing-past-five-day/</link> 
 <description xml:lang="en">1 Canadian Dollar = 1.0378 USD (USD = U.S. dollar (close)). These are the Bank of Canada's nominal closing exchange rates, published at about 4:15 ET each business day. These are neither buying nor selling rates, and should be used for reference purposes only.</description> 
 <dc:date>2011-05-09T16:15:00-04:00</dc:date> 
 <dc:language>en</dc:language> 
 <cb:statistics>
  <cb:country>CA</cb:country> 
  <cb:exchangeRate> 
  <cb:value decimals="4">1.0378</cb:value> 
  <cb:baseCurrency>CAD</cb:baseCurrency> 
  <cb:targetCurrency>USD</cb:targetCurrency> 
  <cb:rateType>Bank of Canada closing rate</cb:rateType> 
  <cb:observationPeriod frequency="daily">2011-05-09T16:15:00-04:00</cb:observationPeriod> 
 </cb:exchangeRate>
</cb:statistics>
</item>
</rdf:RDF>

and I'm trying to do this

XmlNamespaceManager manager = new XmlNamespaceManager(xmlDoc.NameTable);
manager.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
manager.AddNamespace("cb", "http://centralbanks.org/cb/1.0/");
manager.AddNamespace("dcterms", "http://purl.org/dc/terms/");
manager.AddNamespace("xsi", "http://www.w3c.org/2001/XMLSchema-instance");
XmlNode valueNode = xmlDoc.SelectSingleNode("descendant::cb:value", manager);
string v = valueNode.InnerText;

to select the value node, but it just returns null. It has been working for months, but I suppose they changed the document in some way (but I unfortunately don't have an old copy).

Many thanks for any tips

1 Answer 1

4

I noticed the namespace for the cb alias in the xml is:

http://www.cbwiki.net/wiki/index.php/Specification_1.1

While you are using:

http://centralbanks.org/cb/1.0/

for your namespace manager.

Updating the namespace in your code might solve the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.