There are two main reasons for this:

1. In a layout XML, your XML tree contains tags corresponding to classes to
instantiate and the the attributes are parameters passed to those classes.
Since this is sitting on top of an OO model, the specific class
corresponding to the tag will have an arbitrary number of base classes,
implemented by an arbitrary number of authors.  Yet all of those classes
will be pulling their arguments out of the single set of attributes, so
namespaces allow us to avoid any conflicts as the different implementations
change in version.

2. This allows for a number of key optimizations we do to be able to much
more efficiently parse these XML resources, without the requiring that the
tools have DTD descriptions (and actually more than full) of every kind of
XML file you create.  These optimizations come into play when the resource
compiler sees an attribute in a sub-namespace of
http://schemas.android.com/apk/res/..., and include things like:

- The corresponding resource ID of the attribute is embedded in the compiled
XML, so it can be find with simple integer comparisons.

- Multiple such attributes are sorted in order of their resource IDs, so
obtainStyledAttributes() can be performed as an O(N) operation (this is the
reason for the funky way that API works).

- The resource compiler uses the type information associated with the
attribute resource to pre-parse its value, such as converting color and
integer strings to 4-byte ints, converting enums and flags to their final
int value, resolving references to resources or attributes to their
associated resource identifier, etc.

Without these things, there is just no way we could have used generic XML
files for layouts and such and achieved sufficient performance; we would
have had to take a more traditional approach of converting the resource
source files (which could still be XML) into some custom specific binary
blob for that specific resource type.  With what we have now, the full XML
data is parsed on the device, just using our own special binary XML format.

Hope that helps!

On Sat, Jan 31, 2009 at 7:38 PM, Raja Nagendra Kumar <
nagendra.r...@gmail.com> wrote:

>
> Thank you for reply. Any good reason for doing it..
>
> Most of the designs aim to assume reasonal defaults to min typing and
> do more with less..
>
> Regards,
> Nagendra
> >
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to