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.bankofcanad a.ca/stat/fx-xml.xml");
doc.Save("c:\\t emp\\myrates.xm l");
}
}
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:styleshe et 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="Observat ion_date">
<date><xsl:valu e-of select="."/></date>
</xsl:template>
<xsl:template match="Observat ion_data">
<rate><xsl:valu e-of select="."/></rate>
</xsl:template>
<xsl:template match="Observat ion">
<Currency>
<xsl:apply-templates select="*"/>
</Currency>
</xsl:template>
<xsl:template match="Currency _name">
<name><xsl:valu e-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.bankofcanad a.ca/stat/fx-xml.xml");
XslTransform tran = new XslTransform();
tran.Load("tran sform.xsl");
XmlTextWriter output = new XmlTextWriter(" myrates.xml",
Encoding.UTF8);
output.Formatti ng = Formatting.Inde nted;
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 XslCompiledTran sform(true) as follows:
XslCompiledTran sform tran = new XslCompiledTran sform(true);
"Miles Cousens II" <mc******@clear water.ca> wrote in message
news:%2******** ********@TK2MSF TNGP10.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