A little while ago I noticed the SAX dot NET project was announced on the XML-DEV mailing list. From the desxcription on the project page

SAX dot NET is a C# port of the original Java based SAX API specifications. When compiled into a .NET assembly it becomes available to the other .NET languages as well.

The .NET Framework doesn't ship with an implementation of a SAX push model XML parser but instead ships with the pull-model parser in the form of the System.Xml.XmlReader class. The primary reasons for this can be gleaned from my article A Survey of APIs and Techniques for Processing XML where I list the pros and cons of various approaches for processing XML. The main advanatages a pull-model XML parser like the XmlReader have over a push model XML parser like SAX are

Pull model parsers typically do not require a specialized class for handling XML processing since there is no requirement to implement specific interfaces or subclass certain classes for the purpose of registering callbacks. Also the need to explicitly track application states using boolean flags and similar variables is significantly reduced when using a pull model parser

I can understand that developers migrating to the .NET Framework from Java platforms or MSXML would like to have the familiar feel of the SAX API so I definitely welcome such projects. However I have seen some criticism of the project from Daniel Cazzulino, a Microsoft XML MVP, in his post Do we need SAX for .NET? (or does Java ports to C# make sense?) he points out of some of the disadvantages of blindly porting an API from one platform to another. He points out some inconsistencies and redundancies between SAX dot NET and the .NET Framework such as

  • There  is an XmlNamespaces class that does the same thing as the System.Xml.XmlNamespaceManager class

  • There are IAttributes AND IAttributes2, and the corresponding implementations called AttributesImpl and AttributesImpl2 which seem to imply interface versioning problems and legacy issues in a brand new project.

  • The existence of non-standard delegates such as OnPropertyChange(IProperty property, object newValue)  instead of the  typical pattern in the .NET world where it should be OnPropertyChange(object sender, ProperyChangeEventArgs e).

I think Daniel raises good points and encourage any developer porting an API to the .NET Framework to endeavor to make it consistent with the patterns and naming conventions in the .NET Framework. Doing so makes it easier for developers to understand how to use the API since it will be familiar and contains few surprises.  


 

Saturday, 03 April 2004 03:18:11 (GMT Daylight Time, UTC+01:00)
One problem with the pull model parser in .NET is that it doesn't return a node until you have at least one token beyond the node.

This makes it useless for implementing XMPP (the protocol that Jabber is based on, now an IETF standard).

It's more an implementation detail in the pull parser that exists now, but it seems that it's not viewed as a problem and isn't going to change... so anyone wanting to work with XMPP has to find a SAX parser.
Saturday, 03 April 2004 03:54:12 (GMT Daylight Time, UTC+01:00)
Steve,
I'm not familiar with XMPP but I find it unusual to imagine that there is an XML format that cannot be handled by a pull-model parser as well as it can be handled in SAX. Can you provide an example of a fragment of XMPP input that cannot be handled by the XmlReader?
Comments are closed.