This will make a local copy of the XML data:
using System;
using System.Xml;
class Program {
static void Main(string[] args) {
XmlDocument doc = new XmlDocument();
doc.Load("http://www.bankofcanada.ca/stat/fx-xml.xml");
doc.Save("c:\\temp\\myrates.xml");
}
}
If you also need to do a transform of some sort, you might want to use XSLT.
For example, the following XSLT program:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="xsi">
<xsl:template match="/">
<Currencies>
<xsl:apply-templates select="*"/>
</Currencies>
</xsl:template>
<xsl:template match="Observation_date">
<date><xsl:value-of select="."/></date>
</xsl:template>
<xsl:template match="Observation_data">
<rate><xsl:value-of select="."/></rate>
</xsl:template>
<xsl:template match="Observation">
<Currency>
<xsl:apply-templates select="*"/>
</Currency>
</xsl:template>
<xsl:template match="Currency_name">
<name><xsl:value-of select="."/></name>
</xsl:template>
</xsl:stylesheet>
converts the about XML into the following output format:
<Currencies>
<Currency>
<name>U.S. dollar</name>
<date>2005-08-04</date>
<rate>1.212</rate>
</Currency>
...
You can invoke this XSLT program from C# code as follows:
using System;
using System.Xml;
using System.Xml.Xsl;
using System.Text;
class Program {
static void Main(string[] args) {
XmlDocument doc = new XmlDocument();
doc.Load("http://www.bankofcanada.ca/stat/fx-xml.xml");
XslTransform tran = new XslTransform();
tran.Load("transform.xsl");
XmlTextWriter output = new XmlTextWriter("myrates.xml",
Encoding.UTF8);
output.Formatting = Formatting.Indented;
using (output) {
tran.Transform(doc, null, output);
}
}
}
There's a nifty XSLT debugger included with
http://lab.msdn.microsoft.com/vs2005/ that allows you to step right into the
above Transform() call so you can see what the XSLT program is doing. All
you have to do to enable debugging is replace "new XslTransform" with the
new XslCompiledTransform(true) as follows:
XslCompiledTransform tran = new XslCompiledTransform(true);
"Miles Cousens II" <mc******@clearwater.ca> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I would like to be able to import the following xml document on a daily
basis to get the current exchange rates and then create the same output
file
so
I can use Biztalk 2002 to import that file, but I am not sure how to do
it?
Any ideas would be greatly appreciated.
http://www.bankofcanada.ca/stat/fx-xml.xml