2

When we develop layouts in Android all the xml files begin with

xmlns:android="http://schemas.android.com/apk/res/android"

What does this do and why for developing application my xmlns refers to a link in the web ?

PS : This is a newbie question

user2817836
  • 205
  • 2
  • 6

3 Answers3

1

xmlns is xml name space

The namespace is defined by the xmlns attribute in the start tag of an element. The namespace declaration has the following syntax. xmlns:prefix="URI".

xmlns:android

Defines the Android namespace. This attribute should always be set to "http://schemas.android.com/apk/res/android".

http://www.w3schools.com/xml/xml_namespaces.asp

Here's a list of similar question's

What does "xmlns" in XML mean?

Why this line xmlns:android="http://schemas.android.com/apk/res/android" must be the first in the layout xml file?

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

It is just like defining a namespace in C++,

A good explanation can be found here:

Why this line xmlns:android="http://schemas.android.com/apk/res/android" must be the first in the layout xml file?

Community
  • 1
  • 1
Se Won Jang
  • 773
  • 1
  • 5
  • 12
0

You need to use the namespace in case you use your own attributes for the views.

This is most commonly used when you create your own (or use others) customized views.

For example, if you create your own customized textView which supports using a custom font from the assets folder, you might want to add this:

<...MyTextView app:fontFile="fonts/myFont.ttf" .../>

Basically if you wont use the xmlns(ns: name space) ,there could be a conflict between the tag used in another xml file . for eg:

file1:

<table>
  <name>jad</name>
</table>

file2:

<table>
  <tr>
    <td>google</td>
  </tr>
</table>

If these XML fragments were added together, there would be a name conflict. Both contain a element, but the elements have different content and meaning.

For this major reason a qualified name space is used . There are other several use also .