SeekingAlpha
SeekingAlpha

Reputation: 7817

Android and XML

I am new to Android development (just started today). I am familiarising myself with XML which is new to me. I would really appreciate it if people can help me understand this language.

Please see the XML code I am referring to below:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_search"
    android:icon="@drawable/ic_super"
    android:title="@string/action_search" 
    yourapp:showAsAction="ifRoom|withText" />

</menu>

Questions:

1) What is the best way to think of XML code? My understanding is that they are like trees. Should I think of it like the file systems where there are hierarchies etc?

2) I am not sure what the namespace usage is for. For example:

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:yourapp="http://schemas.android.com/apk/res-auto" > 

does this mean that the menu tag contains xmlns:android attribute and a xmlns:yourapp attribute?

3)I would really like to learn how to use XML more proficiently, any links to resources will be much appreciated (I tried w3 but it really was not answering the questions I had.

4) What do the ":" mean/do. The rest of the code I understand. As the API explains it quite clearly but my basic understanding of XML is preventing me from fully understanding the code.

Upvotes: 3

Views: 125

Answers (2)

Phonon
Phonon

Reputation: 12737

  1. Yes, you can think of it as a nested structure, much like the tree of a file system
  2. Yes, it means that menu has two of those attributes. For more information about namespaces, reference this post.
  3. Without knowing what questions W3 didn't help you with, it's hard to tell what it is that you're looking for. XML is very straightforward. There isn't more to it than meets the eye.
  4. The colon in foo:bar means that bar is in the foo namespace.

Upvotes: 0

LeMoN.xaH
LeMoN.xaH

Reputation: 571

Questions:

1) What is the best way to think of XML code? My understanding is that they are like trees. Should I think of it like the file systems where there are hierarchies etc?

-- no xml is data tags so there are opening and closing tags and self contained flags like : will discribe your fridge and if you have multiple dairy products and some veggies in the fridge it will look like this

<Fridge>
   <Dairy>
      <Milk />
      <Cheese />
   </Dairy>
   <Veggies>
      <Carrots />
      <Pumpkin />
   </Veggies>
</Fridge>

2) I am not sure what the namespace usage is for. For example:

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:yourapp="http://schemas.android.com/apk/res-auto" >

does this mean that the menu tag contains xmlns:android attribute and a xmlns:yourapp attribute?

so the xmlns is xml namespace and they are defined in schemas like a deffinition of what attributes there can be and namespaces combine a bunch of defined attributes like :

<menu xmlns:android .. 
  android:name=""
  android:orderId="5"
  />

the android schema namespace describes all the attributes that android platform knows about and you can then access them but using android: and then the attributes that is known for that menu type

3)I would really like to learn how to use XML more proficiently, any links to resources will be much appreciated (I tried w3 but it really was not answering the questions I had.

the XML in android isn't XML that you would use elsewhere android only uses XML to describe how the screens and menus should look like and behave and the best place to learn more about how android uses xml is to look at developer.android.com and try to look at linear layout and learn from there

4) What do the ":" mean/do. The rest of the code I understand. As the API explains it quite clearly but my basic understanding of XML is preventing me from fully understanding the code.

the : in "that:this" is use this attribute from that namespace and the namespaces are defined with xmlns:NAMEDITWHATEVER="schema location" NAMEDITWHATEVER:attribute1="what ever this attribute describes"

Upvotes: 1

Related Questions