01 05 - introduction xml
-
Upload
siva-reddy -
Category
Technology
-
view
111 -
download
1
description
Transcript of 01 05 - introduction xml
![Page 1: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/1.jpg)
Xml Introduction
![Page 2: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/2.jpg)
Agenda
Xml Introduction
![Page 3: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/3.jpg)
XML
eXtensible Markup Language
Simple text (Unicode) underneath
Tags (like in HTML) are used to provide
information about the data
Similar to HTML, but:
HTML is used to describe how to display the data
XML is used to describe what is the data
Often used to store and transfer data
![Page 4: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/4.jpg)
HTML Example
<html>
<head><title>Here goes the
title</title></head.
<body>
<h1>This is a header</h1>
Here goes the text of the page
</body>
</html>
• Tags mean
something specific
to the browser
• They are used for
display
![Page 5: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/5.jpg)
XML Example
<?xml version=“1.0”/>
<person>
<name>
<first>Jose</first>
<last>Barrios</last>
</name>
<email>[email protected]</email>
<phone 555-456-1234 />
</person>
• Tags mean
whatever the user
wants them to
mean
• They are used to
describe the data
![Page 6: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/6.jpg)
XML Rules
Tags are enclosed in angle brackets.
Tags come in pairs with start-tags and end-tags.
Tags must be properly nested.
<name><email>…</name></email> is not allowed.
<name><email>…</email><name> is.
Tags that do not have end-tags must be terminated by a ‘/’.
Document has a single root element
![Page 7: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/7.jpg)
XML Documents are Trees
person
nameemail phone
first last
![Page 8: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/8.jpg)
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloandroid"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloAndroid"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
![Page 9: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/9.jpg)
Using @ in XML Layouts
![Page 10: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/10.jpg)
Attaching Layouts to Java Code
Assume res/layout/main.xml has been created. This layout could be called
by an application using the statement
setContentView(R.layout.main);
Individual widgets, such as my Button could be accessed by the
application using the statement findViewByID(...) as in
Button btn= (Button) findViewById(R.id.myButton);
Where R is a class automatically generated to keep track of resources
available to the application. In particular R.id... is the collection of widgets
defined in the XML layout.
![Page 11: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/11.jpg)
Attaching Layouts to Java Code
Assume res/layout/main.xml has been created. This layout could be called
by an application using the statement
setContentView(R.layout.main);
Individual widgets, such as my Button could be accessed by the
application using the statement findViewByID(...) as in
Button btn= (Button) findViewById(R.id.myButton);
Where R is a class automatically generated to keep track of resources
available to the application. In particular R.id... is the collection of widgets
defined in the XML layout.
![Page 12: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/12.jpg)
Attaching Layouts to Java Code
Attaching Listeners to the Widgets
The button of our example could now be used, for instance a listener for
the click event could be written as:
![Page 13: 01 05 - introduction xml](https://reader036.fdocuments.us/reader036/viewer/2022062419/5585d7add8b42a7c428b492c/html5/thumbnails/13.jpg)
Questions?