Search code examples
xmlxml-namespaces

What does "xmlns" in XML mean?


I saw the following line in an XML file:

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

I have also seen xmlns in many other XML files that I've come across.

What is it?


Solution

  • It defines an XML Namespace.

    In your example, the Namespace Prefix is "android" and the Namespace URI is "http://schemas.android.com/apk/res/android"

    In the document, you see elements like: <android:foo />

    Think of the namespace prefix as a variable with a short name alias for the full namespace URI. It is the equivalent of writing <http://schemas.android.com/apk/res/android:foo /> with regards to what it "means" when an XML parser reads the document.

    NOTE: You cannot actually use the full namespace URI in place of the namespace prefix in an XML instance document.

    Check out this tutorial on namespaces: http://www.sitepoint.com/xml-namespaces-explained/