Errr, some catchy title.... RSS 2.0
 Monday, July 09, 2007

Here is an essay I wrote for my Masters course. I think it could be an interesting read...

 

"Comparison between DTD and XML Schemas"

 

Introduction

Document Type Definition (DTD) and XML Schema are XML schema languages, therefore both of them are used to express a set of rules to which an XML document must conform in order to pass validation. We need schema languages in order to check whether a given document conforms to all the rules given business must enforce.

DTD is native to XML schema language. It has been around for a long time; however it has some shortcomings which will be discussed later.

XML Schema has been developed later with the same purpose as DTD in mind; however it tries to negate DTD’s shortcomings. Furthermore, XML Schema is the first schema language that has been recommended by W3C (World Wide Web Consortium). An instance of XML Schema is called XML Schema Definition (XSD). As, XSD has been designed later it isn’t as limited in functionality as DTD.

DTD versus XML Schema

DTD lacks a couple of important constructs that are vital to working with XML documents. The biggest concern is that DTD syntax is based on SGML not the XML itself. Therefore from the technological standpoint, there is a need for two parsers. First one to validate XML file (just for structure integrity, not for conforming to set rules) and the second one to validate DTD file (again, just the structure). XSD is simply an XML file; therefore we can validate structural integrity of the XSD and the target XML document with just one parser.

As DTD was designed to be a schema language it is very troublesome, that it lacks a very important feature. It lacks data typing. It is impossible to specify what should be the type of the given element. For example it is impossible to enforce a rule that the amount of transaction is of type double. One could still pass a string and DTD parser would state that the XML document is valid. In XSD, one is actually forced (it is a required attribute) to specify the type of an object for each element; hence this problem has been completely mitigated in XSD. XSD also has type called ‘anyType’ for those special situations when type is not important, or it differs for different documents.

Another important shortcoming of DTD is the fact that it is impossible to specify the number of occurrences of a given element. Therefore, a lot of the validation must still be done even after the parser says that the given document conforms to the DTD schema. XSD on the other hand has properties: ‘minoccurs’ and ‘maxoccurs’ which obviously are not perfect but are definitely a step in the right direction. Of course, there are situations where these properties will not be sufficient to specify the business rules required and again the work lies on the shoulders of the developer that must check whether the file corresponds to the standards.

Since the creation of DTD, XML has evolved, newer constructs have been created. Unfortunately, DTD has not been up to par with those. An important feature of XML files are namespaces. They have been created due to the fact the XML has become a mainstream standard and therefore the documents have started to grow very large. It is not uncommon for a document to use two different set of vocabularies. If those vocabularies have the elements with the same name then it would lead to unmanageable files. Creation of XML namespaces has solved those problems. Unfortunately, there is no support for XML namespaces in DTD. This is a big limitation in most modern systems they are simply a must. On the other hand when creating an XSD file, one must specify the namespace of the specification. This and the fact that since XSD is an XML file and has its own namespace shows that this feature of XML documents is deeply supported.

Corollary

DTD is an old technology (it is based in SGML which was developed in 1960s). XML Schema came into being when XML became very popular and it became clear that DTD cannot meet the needs of the businesses. XSD was developed with all the shortcomings of DTD in mind. It was supposed to mitigate all the problems that DTD has. It is believed that the XML Schema is the successor of Document Type Definition.

To sum up, there are a lot differences between the two technologies, even though they attempt to solve the same problem. It is important to note, that even though XML Schema seems far more superior it is simply because it was developed much later then DTD. Most legacy systems still use DTD, however new systems tend to lean toward the usage of XML Schema. To ease in this transition there are a lot tools that allow translating DTD files into XSD format.

Monday, July 09, 2007 7:01:17 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Other
 Thursday, June 28, 2007

So, you wrote your first RIA and you want to publish in on the web and start counting those millions of dollars coming in. You deploy your application, type in the link but, nothing happens. Why?

 

 

 

It could be, that your hosting service doesn’t support .xaml files (mine started around a month age). There is a quick workaround for that, simply rename your .xaml files to .xml. You have to update your references accordingly, such as when you create your xaml object via JavaScript. Luckily, if you do that, everything still works (Intellisense) inside Visual Studio so if you do this before deployment, you won’t have any problems.

 

Note: You don’t have to do this for User Controls as they are compiled into the binary file.

 

Let’s assume that you have created your Silverlight project that consists of one Page.xaml file some User Controls, one Default.html page (so typical set up in Visual Studio). Below is a list of files that need to be uploaded to the server:

 

Default.html

Default.html.js

Page.xaml (or Page.xml)

Silverlight.js

 

And the most important one:

ClientBin (the directory in which is the client DLL)

Thursday, June 28, 2007 10:16:01 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Silverlight
 Monday, June 11, 2007

I was writing a short project for myself in Silverlight that involved calling my own web service. Everything was working great in localhost, however when I uploaded it to my website, the application crashed and I had no idea why. After some time spent debugging (not the most pleasant thing in Silverlight I found out, that calling a web service from generated an exception:

 

Request format is unrecognized for URL unexpectedly ending in /MyMethod.

 

After looking at the problem, I realized that HTTP GET and HTTP POST Are Disabled by Default starting from ASP .NET 2.0. A quick fix has solved the problem, paste the following in the web.config and you’re good to go.

 

<system.web>

    <webServices>

        <protocols>

            <add name="HttpGet"/>

            <add name="HttpPost"/>

        </protocols>

    </webServices>

Monday, June 11, 2007 12:55:07 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Silverlight
 Wednesday, June 06, 2007

I moved my blog from www.greatestcoder.com to www.greatestcoder.com/blog/. If you will hit the first page though, you will be automatically redirected to the second page. Here’s how you can do it in the easiest way possible. Create index.html with the following content:

 

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title title="Marcin Waligora" />

    <meta http-equiv="refresh" content="0;url=http://www.greatestcoder.com/blog/" />

</head>

<body>

</body>

</html>

 

The only thing that is interesting here is the meta tag.

 

http-equiv="refresh"

 

This attribuge will tell the server that the page is going to be redirected.

 

content="0;url=http://www.greatestcoder.com/blog

 

Here we have two things into consideration – 0 indicates the amount of time (in seconds) how long the client should wait before being automatically redirected to another page (here idicated by the url tag).

 

On a lot of pages you will see some information, like : “we’re going to redirect you to a different page in 5 seconds. Click here if you don’t wish to wait”.

 

After moving the application I had one problem, all the pictures that I’ve embedded in the posts were using absolute path. So when I moved my application, none of the pictures were displayed. I had to update my previous posts to reflect this change. It would seem logical (if you’re adding your own copy of the image) to the post that it should use relative path instead of absolute. Then, moving a blog to a new location would be a matter of copying all the files.

 

Hey, this sounds like a feature request for das blog guys J.

Wednesday, June 06, 2007 2:27:40 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Html
 Friday, May 04, 2007

There are examples how to set image to the Image object in Silverlight (both in 1.0 and 1.1); however I haven’t found one how to set it to any object that can be filled. The beauty of XAML based applications is that you can put whatever media you want inside objects, so if you want to fill in Ellipse or a Path with an image you can. The easiest way to do it is just declaratively, in XAML:

 

<Rectangle x:Name="mainPic" Width="448" Height="386" Canvas.Left="288">

      <Rectangle.Fill>

            <ImageBrush ImageSource="pic.jpg" />

      </Rectangle.Fill>

</Rectangle>

 

 

This is great for static content, but what if you want to set it programmatically using Downloader object.

 

Below is the solution for 1.0 (I tested in on Feb CTP release)

 

var wpfe;

 

function root_Loaded(sender, args) {

      wpfe = document.getElementById("wpfeControl1");

     

      mainDownloader = wpfe.createObject("Downloader");

      mainDownloader.completed = "javascript:mainDownloadCompleted";

      mainDownloader.DownloadProgressChanged = "javascript:mainDownloadProgressChanged";

     

      mainDownloader.open("GET", "SomePic.JPG", true);

      mainDownloader.send();

     

}    

 

function mainDownloadCompleted(sender, args) {

    sender.findName("mainPic").Fill.ImageSource = sender.Uri;

}

 

 

Apart from setting the downloader, the most important code line is this:

 

    sender.findName("mainPic").Fill.ImageSource = sender.Uri;

 

When the image gets downloaded we set the Rectangle’s ImageBrush to its URL.

 

Now solution for 1.1 in C#:

 

public void Page_Loaded(object o, EventArgs e)

        {

            // Required to initialize variables

            InitializeComponent();

 

            Downloader downloader = new Downloader();

            downloader.Completed += new EventHandler(downloader_Completed);

            downloader.Open("GET", new Uri("SomePic.JPG", UriKind.Relative), true);

            downloader.Send();

        }

 

 

void downloader_Completed(object sender, EventArgs e)

        {

           (mainPic.Fill as ImageBrush).ImageSource = (sender as Downloader).Uri;

        }

 

Once again, the most important code line is this

 

(mainPic.Fill as ImageBrush).ImageSource = (sender as Downloader).Uri;

 

Notice, how much casting we have to do, because C #is a strongly typed language.

 

Hope this helps.

Friday, May 04, 2007 3:15:45 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Silverlight

This is a quick post describing my first impressions with Silverlight 1.1 and Orcas Beta 1.

 

Orcas:

·        Overall: a step forward in a good direction. I really enjoy working with it. Can’t wait for Resharper to come out for it J.

·        I love that I can finally debug JavaScript.

·        Nice and clean separation: When you have Page.html, you also get Paga.html.js. Now, we have code behind for everythingJ.

·        XAML explorer is a lot faster when I compare it to VS 2005.

·        Running Silverlight application launches default browser in the system (in my case Opera). There is no plugin for Opera to make Silverlight working, so I always get the lovely image Get Silverlight. I had to set IE to be my default browser. In VS 2005 IE launched always no matter what was the default browser, I preferred it that way.

·        Ctrl + Right Arrow (and Ctrl + Left Arrow) don’t work! When I checked keyboard shortcuts in 2005 and Orcas they said exactly the same thing: Edit.MoveControlRight. Apparently this doesn’t work in Orcas on my machine. BTW: I had no idea how much I use this feature until it stopped working.

 

 

 

Silverlight:

  • Between 1.0 and 1.1 a HUGE step forward. I mean CLR on MAC, DLR and so on. My head still hurts….
  • It’s amazing I can write C# in my client app. I’ve written an Image Gallery for Silverlight 1.0 (actually when I wrote it, it was still WPF/E) and it wasn’t a joy ride. I didn’t enjoy debugging JavaScript with alert.
  • I’m rewriting it now to learn 1.1 and I’ve noticed that productivity boost is amazing. I truly believe that it will be possible to write simply amazing Rich Internet Applications with this technology.

 

 

Small Tip when building Silverlight applications with Orcas:

 

When you’re adding objects to XAML code that you want to reference in the code behind, make sure you use prefix x before Name property:

 

<Rectangle x:Name="mainPic" Width="448" Height="386" />

 

x of course corresponds to

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

Without that little x you will get compilation errors. It is a little bit counter intuitive since when you press n you also get a property Name, but this Name corresponds to the default schema

 

 

 

Friday, May 04, 2007 2:41:01 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Orcas | Silverlight
 Friday, April 20, 2007

When you’ve used ASP.NET AJAX’s UpdatePanel you may have come across this error. Its typical message is:

 

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

 

 

 

 

 

If you get this error, the first thing everyone does is to check whether they have any of the things they were not supposed to be doing:

  • Calling Response.Write()
  • Using response filters or HttpModules
  • Having Server Trace enabled.

 If you check those things and are positive that they are not the case, you’re lost. Well as it turns out, there’s a fourth hidden option:

 

Calling Server.Transfer method.

 

The thing is, when you call Server.Transfer, the server generates HTML for the next page and sends it directly to the client which was expecting some part of the page that was supposed to be returned via AJAX. This generates PageRequestManagerParserErrorException. So, you cannot use Server.Transfer method.

 

Well, actually you can, but it cannot be an asynchronous call.

So if the button is inside the UpdatePanel it will automatically use asynchronous calls. Luckily, there are two ways to force it to make a full postback.

  1. If the button is created statically, then simply register it a as a PostBackTrigger.
  2. If the button is created dynamically, call ScriptManager.RegisterPostBackControl with the necessary button.
Friday, April 20, 2007 1:36:07 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Ajax | ASP.NET AJAX
 Tuesday, March 27, 2007

I was writing a Powershell script today to automate deployment for application we’re currently working on. Part of the requirement was to get latest files from Visual Studio SourceSafe. VSS provides us only with COM wrappers; however I wanted to do that via .NET objects.

 

Luckily googleing the problem has produced some valid resources. Check out VSS Code Samples. From there, download OLE Sample Code Written in Visual Basic .NET and C#. This exe contains a .NET solution with 2 projects: .NET VSS Library written in C# and a VB.NET explorer application that is basically a VSS Explorer that uses the Library under the hood. The problem is this has been written for version 6 of VSS and I had version 8 (the 2005 release).

 

Due to this, the explorer application couldn’t compile, since it relied on some ActiveX that simply wasn’t there anymore. Luckily, the underlying VSS Library still worked. Below is a sample code that I used to do my small task with the VSS Library. The code gets all items (recursively) from the given path.

 

clIVSSLibrary lib = new clIVSSLibrary();

string errorOccured = null;

errorOccured = lib.OpenDB("Martin.Waligora", "somepassword",  "\\192.168.1.75\vss_application");

errorOccured = lib.SetCurrentProject("project");

errorOccured = lib.SetWorkingFolder(@"$/project/DistributionImage", @"C:\VSSTest");

VSSFlags flag = new VSSFlags();

long flags = flag.FlagGetLocalCopyYes() + flag.FlagRecursiveYes()

                        + flag.FlagReplaceLocalReplace() + flag.FlagRights_All();

 

string getPath = null;

errorOccured = lib.GetItem(@"$/project/DistributionImage", ref getPath, (int)flags);

lib.CloseDB();

 

 

After writing the code I’ve added it to my Powershell script. Here’s it:

 

$VssDllPath = 'C:\IVSS_Sample\IVSSDLL\bin\Debug\IVSSLibrary.dll';

"Loading the .NET VSS DLL $VssDllPath"

$ass = [reflection.assembly]::LoadFrom($VssDllPath);

 

"Creating object of type IVSSFunctionLibrary.clIVSSLibrary"

$VssLib = New-Object IVSSFunctionLibrary.clIVSSLibrary;

 

#We create a function to help us with calls to the vss library

function ErrorOccured

{

      if($args[0].Length -gt 1)

      {

            "Error has occured: $args[0]"

      }

}

 

#We insantiated the object, now let's get all data to specified directory

ErrorOccured $VssLib.OpenDB("Martin.Waligora", "fakepass", "\\192.168.1.75\vss_app");

"Starting to copy all the files"

ErrorOccured $VssLib.SetCurrentProject("project");

ErrorOccured $VssLib.SetWorkingFolder("$/project/DistributionImage", $remotePath);

#$flags = 67117199;

$getPath = "";

ErrorOccured $VssLib.GetItem("$/project/DistributionImage", [ref] $getPath, 67117199);

ErrorOccured $VssLib.CloseDB();

"Success, finished copying files to $remotePath";

Tuesday, March 27, 2007 4:02:45 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Powershell
 Monday, March 26, 2007

Last week I've passed 70-229 exam by Microsoft. It was the final one out of 5 exams required. Hence, now I am Microsoft Certified Solution Developer and I can use those logos (MCAD is a subset of MCSD):

 

                                                                 

 

To sum up: Awesome :D .....

Monday, March 26, 2007 4:27:00 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Other
 Thursday, March 22, 2007

I just finished week long second trimester of my Masters course. The module was about Design Patterns. Every day we had lectures in the morning and then labs in the afternoon. During the lectures we went through most of the Gang of Four patterns, they were pretty interesting even though I knew most of the stuff. What I really loved about the course were the labs.

 

Every day we were given some working application and we were supposed to apply some specific pattern to extend the functionality of the application. I always believed, that it’s impossible to learn design patterns just by reading a book, you gotta look at the code and try to incorporate it into it, or just ‘get it’. What was good about the exercises in the lab is the fact that the applications were easy enough to understand their inner workings immediately, but complicated enough to see, that some pattern would help here a lot.

 

Oh yeah, and I was able to refresh my memory of Java and Swing. Win-win situation.

Thursday, March 22, 2007 3:00:34 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Other
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Marcin Waligora
Sign In
All Content © 2008, Marcin Waligora
DasBlog theme 'Business' created by Christoph De Baene (delarou)