Generating code with XSLT from a DataSet

One of the great things about a DataSet, from a code generation perspective that is, is that it is defined in an XML Schema with some added features for TableAdapters and such. I wrote a very simple code generator that takes a DataSet definition and an XSLT stylesheet and generates a code file. I also made it possible to call an XSLT stylesheet for each table in the DataSet so I could create Data Transfer Objects and such from the table definition. I had some trouble to get it going though because of a namespace issue. The namespace that you expect to be the default namespace isn’t in actual fact as I’ll explain with the following fragment:

<xs:schema id=”TrackingTracingDataSet”
targetNamespace=”http://tempuri.org/MyDataSet.xsd”
xmlns:mstns=”http://tempuri.org/My.xsd”
xmlns=”http://tempuri.org/MyDataSet.xsd”
xmlns:xs=”http://www.w3.org/2001/XMLSchema”
xmlns:msdata=”urn:schemas-microsoft-com:xml-msdata”
xmlns:msprop=”urn:schemas-microsoft-com:xml-msprop”
attributeFormDefault=”qualified” elementFormDefault=”qualified”>
<xs:annotation>
<xs:appinfo source=”urn:schemas-microsoft-com:xml-msdatasource”>

From the above fragment you would think that the default namespace is http://tempuri.org/MyDataSet.xsd, because the default namespace is declare with the statement xmlns=”http://tempuri.org/MyDataSet.xsd. The actual default namespace is however defined in the source attribute of xs:appinfo element, so the default namespace is urn:schemas-microsoft-com:xml-msdatasource.

Leave a Reply

Your email address will not be published. Required fields are marked *