January 28, 2003
@ 11:58 PM
Joe asks "For example, what is the shortest piece of code you can write to add a namespaced element to a document through a DOM API?". The answer is two on the System.Xml APIs in the .NET Framework. A sample program setting up his problem and showing the two lines of code is provided

using System;
using System.Xml;

public class Test
   public static void Main() {      
     XmlDocument itemDoc = new XmlDocument();
                        <title>A sunny day</title>
                        <description>Insert witty prose here.</description>

     string xml2Insert = "<dc:date>2003-01-27T22:52:04-05:00</dc:date>";

     //LINE 1: add namespace decl     
     itemDoc.DocumentElement.SetAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");

     //LINE 2: add XML
     itemDoc.DocumentElement.InnerXml =  itemDoc.DocumentElement.InnerXml + xml2Insert;


Reading Carlos's point 79 he mentions that there are umpteen APIs for doing stuff with XML in Java but fails to point out that most of them do the same things and are refactoring of the same ideas over and over again. System.Xml has pull based parsing and model based parsing. We don't have an explicit event based model because one can be built from the pull model parser and I believe Dan Wahlin has an example of that in his book. Either way recent discussions on XML-DEV point out that pull model parsing is superior to event based parsing. As for the umpteen reimplementations of model based representations of XML mentioned (DOM, JDOM, DOM4J, EXML, XOM) all are basically slight variations of the "XML as a tree of nodes" API theme and all of them can't do what I just did above in less lines of code. The same goes for schema tools. As for the rest of his points they are just as John said
the reasons are generic enough to be applied to any language X which has been around longer than language Y.

Most notably, set X = "C" (or C++) and Y = "Java". I got 36 reasons on my first cut and paste pass against 75 original reasons (48%).
This isn't to say that some of his points aren't valid (the 8MB JVM download vs. 20MB for the CLR resonates with me especially now that I have RSS Bandit which I'd like to distribute to non-geek friends) but his points are severely weakened by the number of specious arguments he uses which tend to boil down to Java (the platform not the language) has been around longer then the .NET Framework.

Get yourself a News Aggregator and subscribe to my RSSfeed

Disclaimer: The above comments do not represent the thoughts, intentions, plans or strategies of my employer. They are solely my opinion.