Re: [Saxdotnet-devel] String.Empty vs. null
Brought to you by:
jeffrafter,
kwaclaw
From: Karl W. <ka...@wa...> - 2005-01-13 18:09:08
|
Jeff Rafter wrote: >> One could think of this as a guideline: >> >> - If we would say: this string parameter/argument/value >> can be absent, then let's use null to indicate it. >> - If we would rather say: this string parameter/argument/value >> can be empty, then let's use "" to indicate it. >> >> Coming back to the SAX API: >> How would the above guideline be resolved for namespace URIs >> and prefixes when an XML name is not in any namespace? > > > I think that these are good guidelines-- and tough to argue with... but > for namespace URIs I think there is some ambiguity still... > > a) <foo/> > b) <foo xmlns="http://foo"/> > c) <foo xmlns=""/> > > Most naturally I would see this as > > a) null > b) "http://foo" > c) string.empty Are you asking what to pass for the namespace uri of foo in the StartElementHandler()? a) don't know, depends if there is a default namespace b) "http://foo" c) null (there is no namespace for foo) We really only have two cases: foo has a namespace, or it doesn't. Or did you mean something else? > But I could see this making for needlessly complex handler code. Which > is why we want to land on either null or string.empty. string.empty > gives you less chance of a runtime exception but does not represent case > (a) very well. Using null does not represent (c) very well. I think that > in the XML Corpus this is one of the few areas where "" has a specific > meaning. You brought up arguments about API consistency and should we > use string.empty if no Public ID is provided (for instance)... but what > about the case where you have: > > <foo bar=""> > > Would the bar attribute's value be null or string.empty? String.Empty. null would mean: no value. Karl |