Re: [Saxdotnet-devel] StartElement, when URI is not present
Brought to you by:
jeffrafter,
kwaclaw
From: Karl W. <ka...@wa...> - 2004-12-11 17:35:34
|
Elliotte Harold wrote: > Karl Waclawek wrote: > > >> I can understand this, but you would usually check the Uri anyway, >> since you want to know if the name has a namespace. So you would >> get used to "if (uri == null)" fairly quickly. > > > In fact, I find that I don't do that nearly as often as you'd think. As > long as I know the URI is not null there are a lot of cases where I can > treat the empty space exactly the same as any other namespace. If I had > to worry about it being null, I absolutely couldn't do that and I'd have > to litter my code with a lot of null checks or catch > (NullPointerException). It just works out cleaner to be able to treat no > namespace the same as any other namespace. which I can do most (not all) > of the time if it's the empty string and none of the time if it's null. I had another look at the Java API. It seems it is quite inconsistent with respect to empty string vs. null. Examples: - In EntityResolver, all occurrences of publicId or baseUri are supposed to be null, when absent. - DTDHandler.notationDecl(): publicId, systemId can be null, if not provided - DTDHandler.unparsedEntityDecl: publicId can be null if not provided - DeclHandler.attributeDecl(): mode and value can be null, where in the latter there is actually a semantic difference between value = null (meaning: none defined) and value = empty string (meaning: a value is specified, and it is the empty string). - DeclHandler.externalEntityDecl: publicId can be null, if not provided - LexicalHandler.startDTD(): publicId, systemId can be null, if not declared It actually seems that the prevalent approach is to use null for absence of a string parameter, and only in the case of namespaces does the API stray from this rule. However, I would strongly suggest that we remain consistent in SAX for .NET. If we pick String.Empty, then we need to allow one inconsistency - and that is for the Value parameter passed to the attributeDecl() call-back. Karl |