Does anyone know of an easy way that I can import a remote CSV file via XSLT? I have tried using GetXmlDocumentByUrl but it (quite correctly) errors as the file being loaded is not an XML document. IS there an equivalent for loading non-XML documents from remote locations.
GetXmlDocumentByUrl is only for Xml. If you just want to import a csv file you could use umbImport. I've build a csv option, so you can select a csv file. This is not a remote file.
If you need to access the file dynamicly. You can create an xslt extension that returns the data as an xpathNodeIterator.
public static XPathNodeIterator GetCsv(string filename) { XmlDocument xdoc = new XmlDocument(); XmlElement rows = xdoc.CreateElement("rows"); xdoc.AppendChild(rows);
using (System.IO.StreamReader sr = new System.IO.StreamReader(filename)) { String line; // Read and display lines from the file until the end of // the file is reached. while ((line = sr.ReadLine()) != null) { XmlElement row = xdoc.CreateElement("row"); rows.AppendChild(row); foreach (var item in line.Split(";".ToCharArray())) { XmlElement col = xdoc.CreateElement("col"); col.Value = item; row.AppendChild(col); } } } XPathNavigator xp = xdoc.CreateNavigator(); return xp.Select("/rows"); }
Following on from Thomas' reply, (at present) a custom method is the only way to go.
If you need a quick-and-ready solution to this, and don't want to get involved with Visual Studio (God knows why? We all love it), you can do this all natively in XSLT ... using a custom function (see Extend your XSLT with custom functions wiki page)
Cheers Lee, that was just the sort of start I was hoping for now I can concentrate of dealing with the actual data and displaying it in some kind on meaningful way.
Richard, thanks for your reply regarding umbImport, I've used your fantastic package already when migrating an existing site over to Umbraco so thanks for all your hard work.
Import Remote CSV in XSLT
Does anyone know of an easy way that I can import a remote CSV file via XSLT? I have tried using GetXmlDocumentByUrl but it (quite correctly) errors as the file being loaded is not an XML document. IS there an equivalent for loading non-XML documents from remote locations.
Cheers in advance
Paul.
As far as I know, no.
Write your own xslt extension which loads the csv file into an XmlDocument and returens an XmlNodeIterator.
If you have questions I can give you an example
Thomas
Hi Paul,
GetXmlDocumentByUrl is only for Xml. If you just want to import a csv file you could use umbImport. I've build a csv option, so you can select a csv file. This is not a remote file.
If you need to access the file dynamicly. You can create an xslt extension that returns the data as an xpathNodeIterator.
Hope this helps you,
Richard
Something like that will do it:
hth, Thomas
Following on from Thomas' reply, (at present) a custom method is the only way to go.
If you need a quick-and-ready solution to this, and don't want to get involved with Visual Studio (God knows why? We all love it), you can do this all natively in XSLT ... using a custom function (see Extend your XSLT with custom functions wiki page)
Here's an example:
The "GetCsvByUrl" method doesn't take multi-line (rows) into account... you can quite easily replace this with Thomas' method (above).
Cheers Lee, that was just the sort of start I was hoping for now I can concentrate of dealing with the actual data and displaying it in some kind on meaningful way.
Richard, thanks for your reply regarding umbImport, I've used your fantastic package already when migrating an existing site over to Umbraco so thanks for all your hard work.
Paul
is working on a reply...