Tuesday, December 22, 2009

CodeGenerator From XML Schemas using Visual Studion XSD.exe

XSD.exe is a nice tool for .NET Code-Generation from an existing xml Schema. It's very similar like its java counterpart (JAXB- XJC)


Syntax:

Visual Studio 9.0\VC>xsd /c /out:c:\aneesh\classes c:\Aneesh\dataTypes.xsd

/c stands for generating classes
/out specifies the output directory
/namespace can give a specific namespace for the generated class


A bit complex situation, with multiple schema's

Scenario:

You have an XSD, objectrSchema.xsd and you have another XSD dataTypes.xsd. Some of the DataTypes in the dataTypes.xsd are used in the objectSchema.xsd. In this situation if you run the above command, it will give you a straight error:

Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.
Error: Error generating classes for schema 'c:\ Aneesh\objectSchema.xsd '.

We can overcome this situation with a few tweaks. Thought I searched google but didn’t yield any satisfactory results. These are thing steps I did to make it work.

Step 1:

Import the dataTypes.xsd into the objectrSchema.xsd using the More details of XD IMport can be found here.

Note that the “namespace=http://www.aneesh.com/datatypes “should be the same as the one defined in dataTypes.xsd

Step 2:

Finally hit the command:

Visual Studio 9.0\VC>xsd /c /out:c:\aneesh\classes c:\Aneesh\dataTypes.xsd c:\Aneesh\objectSchema.xsd

Here you go. Your code is generated. Happy Hacking!

More Reading


Thursday, July 23, 2009

HTml Files not Being Served By IIS7

For a few days I was wondering when I moved my customers ASP application from DailyRazor to Godaddy, it simply does not server .html, .txt, .pdf, etc files. The only diference (Though a huge difference) is the change of server fomr IIS6 - IIS7). I called their support just to be answered by an Idiot.

Finally I started my classic debugging.

Started from URLRewriter by YAF.net

I noticed one thing, if the web.config just has the default stuff, everything is fine (Except .aspx because it doesn't have any registered dlls)

So I started removing the tags one by one from the web.config. Finally, understood, the problem lied in this particulr entry:



I still don't remember when I added this part to the web.config.

Also I added the following to the web.config for the html files to be served:

<add validate="false" path="*.html" verb="*" type="System.Web.DefaultHttpHandler"></add>


</remove name="StaticFile"/>

Sunday, March 22, 2009

EventBubble in Javascript

Today I came across a cool method of Javascript. Basically I was trying to fix a long running bug. The underlying issues was something similar:

<tr id="idTR" class="some-Tr-Class" onclick="javascript:Ajsclass.doTRWork();" >

<td class="some-Td-Class" onclick="_do_nothing()">

<input type="checkbox" id="dynamicallyGen" value="xyz">

<td class="some-Td-Class">

..Some title..

</td>

.....
....

</tr>



My Issue is I want to override the Ajsclass.doTRWork();. for the first TD with the checkbox. Was wondering how to
to fix it. Finally Mozilla helped me with their API documentation.

The solution is to not call the bubble function which is Ajsclass.doTRWork(); Just stop after _do_nothing().

The solution is to add:

event.cancelBubble = true;


in the _do_nothing().

The above works fine for Firefox but not for IE


For IE add the following:

event.stopPropagation()


Cool aha? I started liking javascript right from the beginning of this project as 70% of my work was Ajax & JS.