Re: [Saxdotnet-devel] StartElement, when URI is not present
Brought to you by:
jeffrafter,
kwaclaw
From: Elliotte H. <el...@me...> - 2004-12-07 18:41:01
|
Jeff Rafter wrote: > We have been discussing the various possibilities of enforcing a rule > about what to do when a URI is not present. For example consider this: > > <foo></foo> > > What should the StartElement call consist of? > > QName : "foo" > LocalName : "foo" > Uri : null or string.Empty? This really, really, really needs to be the empty string, unless null works very differently in C# than in Java. It's just incredibly useful to be able to assume the namespace URI (and other arguments to this method) are never null. I see this again and again in my SAX work. API quality wise, null should be avoided here. > I am not saying that I am against String.Empty, but from > a programming point of view it is simply a weaker choice. > > - null indicates absence better than picking a special value. > - what if an empty string ever got a special meaning for URIs? It already has a special meaning for URIs and namespace URIs. There's approximately zero chance of this changing. XML-wise these two elements are equivalent: <data /> <data xmlns="" /> Unless you're prepared to use null for both of them, which I think would be harder for implementers, you need to pick the empty string here. Unlike SQL, XML namespaces do not distinguish between the empty string and no value. Namespaces in XML says, "The default namespace can be set to the empty string. This has the same effect, within the scope of the declaration, of there being no default namespace." -- Elliotte Rusty Harold el...@me... XML in a Nutshell 3rd Edition Just Published! http://www.cafeconleche.org/books/xian3/ http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim |