What is SDMX.NET?SDMX is a large and complex standard which makes creating SDMX-capable applications a difficult and error-prone activity. Using an SDMX specific library, which is a complete and accurate implementation of the standard, will enable developers to create robust and production ready SDMX applications. SDMX.NET is that library. - Completely open source.
- Produce and consume SDMX from any data source (like Excel or Database).
- Full and accurate implementation of the supported SDMX artefacts.
- Written in C# and thus compatible with any .NET application.
- Intuitive and easy to use API.
- Optimized for scalability and performance.
ExamplesTo give an idea of what the framework can accomplish, here is a code sample in C# for creating a new dataset, populating it and then saving it in the generic data format. It is important to note that the library ensures that the resulting dataset is 100% valid based on the key family definition and it will prevent the program from accidentally setting a wrong value to the dataset. // Load the dsd with the key family
var dsd = StructureMessage.Load("DSDPath");
var keyFamily = dsd.KeyFamilies[0];
// Create an empty data set for the key family
var dataSet = new DataSet(keyFamily);
// Create new series key
var key = dataSet.NewKey();
key["FREQ"] = (CodeValue)"A";
key["SEX"] = (CodeValue)"M";
key["REF_AREA"] = (CodeValue)"CAN";
// Create a new series using the key
var series = dataSet.Series.Create(key);
// Set the series attribute
series.Attributes["TIME_FORMAT"] = (CodeValue)"P1Y";
// Create observation for year 1999
var obs = series.Create((YearValue)1999);
// Set observation value and its attribute
obs.Value = (DecimalValue)3.32423m;
obs.Attributes["OBS_STATUS"] = (CodeValue)"A";
// Add the observation to series and then to the dataset
series.Add(obs);
dataSet.Series.Add(series);
// create new data message with a header
var dataMessage = new DataMessage();
dataMessage.Header = new Header("MSD_HDR", new Party("UIS"))
{
Prepared = DateTime.Now
};
// set the data set and save with the generic format
dataMessage.DataSet = dataSet;
dataMessage.SaveGeneric("GenericData.xml");
The following example shows how to create a new code list and save it to a file. var codelist = new CodeList(new InternationalString(Language.English, "Countries"), "CL_COUNTRY", "UIS");
codelist.Add(new Code("CAN"));
codelist.Add(new Code("USA"));
var message = new StructureMessage();
message.Header = new Header((ID)"MSD_HDR", new Party((ID)"UIS"))
{
Prepared = DateTime.Now
};
message.CodeLists.Add(codelist);
var doc = new XDocument();
message.Save("CL_COUNTRY.xml");This example shows how to convert from generic to compact data message. // load the keyfamily from the DSD
var dsd = StructureMessage.Load("StructureSample.xml");
var keyFamily = dsd.KeyFamilies[0];
// load the in generic format
var message = DataMessage.LoadGeneric("GenericSample.xml", keyFamily);
// save in campact format with the namespace
message.SaveCompact("CompactSample.xml", "temp", "http://tempuri.org/sdmx");Of course, the framework has many other capabilities like creating other SDMX artefacts and converting between the different data formats. Please feel free to download the code, modify it, and submit feature requests and suggestions.
|