Creating .NET objects for Mapguide XML schema Definitions (XSD) using LINQ

With the release of Mapguide 2007 I was really excited about the new API and the significant power that it would give us developer types.  Though I now appreciate the work involved with creating a full object API for all the supported development platforms, I was a little sad to see that only a handful of objects had been created for working with the various entity types available in Mapguide.

One of my first tasks with Mapguide was to add some layers to the map, before the viewer had loaded up, save that map in the session repository and then build a layout for the map – again in the session repository.  I tried various ways of working with the XML provided by the resource  service, and read through many of the e-mails on the topic from the Osgeo list, but I just couldn’t get it to work.  So I set out on my mission to get an object based method of getting things done.  First, as per the developer documentation I tried out xsd.exe.  XSD allowed me to get a class skeleton created, but there was a lot of work needed to a rounded API running.   I had been recently investigating the new functionality Microsoft was exposing with LINQ – and I came across LINQ to XSD.  For more information on Linq to XSD the is a good place to start. 

So download and install it.  You will need to have installed first.  In addition to that I’m using Visual Studio 2008 Pro.  I have tried these steps with both Mapguide Enterprise 2008 and  2009.  I have to assume the resulting code will work with Mapguide Open Source as well.

Setting up your project

At this point you should be able to fire up Visual Studio and create a new project.  If you are a VB developer, I’m afraid you’re going to have to dive into a bit of C#, as its the only support language right now.  It’s not that bad.

The new project window should look a little like this:


Choose LINQ to XSD Library and give the project a name.  Once the new project is loaded, create a new folder called XSD.  Browse to your Mapguide 2009/OS 2.0 server Schema folder (on a default installation its c:\Program Files\Autodesk\MapGuideEnterprise2009\Server\Schema).  Take a these files and drag them into the new XSD folder.

Back in Visual Studio, select all of the XSD files.  Look in the property window and change the "Build Action" to be "LinqToXsdSchema".

Building the project

At this point, right click on the project in Visual Studio, and choose build.  You should have 173 errors.  This is caused by having multiple, similar versions of some of the XSDs.  Let’s exclude the following files:

  • FdoProviderCapabilities-1.0.0.xsd
  • LayerDefinition-1.0.0.xsd
  • LayerDefinition-1.1.0.xsd
  • LoadProcedure-1.0.0.xsd
  • SymbolDefinition-1.0.0.xsd

Rebuild the project and we should be down to five errors.  I have found that by excluding the following files I was able to get the code to generate:

  • ApplicationDefinition-1.0.0.xsd
  • ApplicationDefinitionInfo-1.0.0.xsd
  • SymbolLibrary-1.0.0.xsd


For my purposes, I was not too concerned about being able to work with these entity types programmatically (at least at this time).  If anyone is able to work around and would like to share it, please let me know.

Page 1 of 3 | Next page