A (175)

(Tuis.) #1
CHAPTER 4: Introduction to XML: Defining an Android App, Its Design, and Constants 103

collections of data used in your app (sort of like a simple database) can also be created and
loaded with their data values using XML files. All of this holds true for XML in 32-bit Android 4 and
64-bit Android 5.


XML markup is contained in simple text format files using an xml file extension. You can create
XML files in a text editor, such as Windows Notepad; however, most programmers usually use a
software editing tool with programming and markup design features, such as Eclipse, IntelliJ, or
NetBeans. These XML files can then be read or “parsed” by the Android OS or your application Java
code, and turned into Java object structures using the XML “definition” in each file.


XML Naming Schema: Tag & Parameter Repository


XML is comprised of “tags” and their “parameters.” Parameters are part of the tags, and are used
to configure and fine-tune what each of these tags accomplishes, as well as to reference any new
media assets, or text fonts, or color values, or styles, or themes, or other XML definitions, and similar
assets that might be required to “skin” or define how that application element appears to your users
on their display screen.


The XML tags and parameters that you can use in a particular framework, such as in Android
development, are specified using an XML “naming schema.” This definition of the XML tags and
parameters is stored in a centralized repository, similar to the one Eclipse accessed in Chapter 2,
when you did a Check for Updates function. That repository hosted the latest Android SDK version
and codebase, whereas the Android XML repository is located at a different URL location (a different
folder) on Google’s Android servers.


The reason that XML needs to have a naming schema is because this language is inherently
designed to be “extensible.” This means there is no “standard” version of XML; each version is
customized for some required implementation (end use) by whatever person or organization needs
to use it. In this case, Android’s XML has been specifically customized for, and implemented for, the
development of Android applications.


As an example, Android OS developers created the XML tag named for designing
Relative Layout designs that ultimately use the Android RelativeLayout Java class and define
RelativeLayout objects. You’ll learn all about what classes and objects are in the next chapter
regarding the Java programming language.


The XML naming schema is referenced inside of each of your XML definition files, at the very top, so
that the XML markup inside of that file can reference its XML naming schema (the customized XML
specification) in order to make sure that all of the tags and parameters used in the XML definition are
up-to-date and “valid.”


This ability to reference the current XML tags and parameters definition (naming schema) is possible
due to the ability to check the XML in the file against the “master definition” represented by the
schema at the remote repository location, although Eclipse ADT does not do this in “real-time”
currently, so you do not need an active Internet connection to be able to develop your XML markup.
This process of making sure that your XML tags and their attributes or parameters are correct (in
conformance with the XML definition) is called XML validation, and it uses an XML naming schema
parameter to accomplish this XML validation.


In any custom extensible markup language, such as the one that has been created by Google for
Android, this naming schema URL reference needs to be contained in the first (outermost) “parent”

Free download pdf