Re: attribute namespace "" or null or both
Aleksander Slominski <[email protected]>
| Newsgroups | gmane.text.xml.xmlpull.devel |
|---|---|
| Message-ID | <[email protected]> |
Stefan Haustein wrote:
> Aleksander Slominski wrote:
>
> > looking on some problems that XmlPull API users have reported
> > i think that it will be beneficial that in case when namespaces are enabled
> > we allow both empty string ("") and null as namespace when retrieving
> > value of attribute that has no namespace
>
> Perhaps we can use null as "joker" matching any namespace,
> like in the require case?
hi,
i think it would be too confusing (and breaking backward compatibility)
- what if "joker" matches more than one attribute?
> > those two would be equivalent: if namespaces are enabled:
> > getAttributeValue ("", name)
> > getAttributeValue (null, name)
> > and if namespaces are disabled
> > getAttributeValue ("", name) will throw IllegalArgumentException
> > getAttributeValue (null, name) works OK
>
> In my opinion, the default namespace ("") should work regardless
> whether namespace support is switched on or not, so in the
> second case both should work OK. Also, disallowing "" when
> namespaces are switched off would break backwards compatibility.
ok. so we have that irregardless of namespace processing on or off
those calls are equivalent:
getAttributeValue ("", name)
getAttributeValue (null, name)
getAttributeValue (NO_NAMESPACE, name) //as NO_NAMESPACE is ""
> While the default namespace is valid for elements, it does not
> help for attribues. Thus, in my opinion, getPrefix should have
> the following signature:
>
> String getPrefix (String namespace, boolean create,
> boolean forAttribute)
>
> getPrefix with create==true and forAttribute==false
> would return "" for the default namespace if it fits
> the namespace parameter, but a newly created namespace
> if forAttribute is set to true?
>
> What do you think?
i do not think it is needed: attributes can be declared
(1) in NO_NAMESPACE (i think we should allow both "" and null)
and no prefix is needed for it. moreover no prefix is even
allowed (namespace URI "" can only be for to default xmlns and no xmlns:prefix)
(2) in non-empty namespace.
if create==false return prefix if namespace is declared or null
(there is interesting case when namespace has more than one prefix:
xmlns:prefix1="foo" and xmlns:prefix2="foo" - what is prefix for namespace "foo"?
if create==true we can always auto generate prefix if needed and declare namespace
how does it sound?
thanks,
alek