Presentation is loading. Please wait.

Presentation is loading. Please wait.

PART 1 XML Basics. Slide 2 Why XML Here? You need to understand the basics of XML to do much with Android All of they layout and configuration files are.

Similar presentations


Presentation on theme: "PART 1 XML Basics. Slide 2 Why XML Here? You need to understand the basics of XML to do much with Android All of they layout and configuration files are."— Presentation transcript:

1 PART 1 XML Basics

2 Slide 2 Why XML Here? You need to understand the basics of XML to do much with Android All of they layout and configuration files are XML files

3 Slide 3 Overview XML is a very simple language The entire specification is only about 35 printed pages XML IS CASE SENESITIVE

4 Slide 4 The XML Document At the heart of XML is the XML document An XML document is a logical entity rather than a physical one One logical document can be stored in different physical files locally and on the Web and assembled somehow A well-formed subset of an XML document is called a document fragment An XML document contains markup (tags) and data Looks like HTML without predefined tags Elements contain 0, 1 or many attributes

5 Slide 5 Elements (Introduction) XML tags resemble HTML tags but they are not predefined That is, you give names to tags just as you give names to variables and other identifiers Starting tags appear as Ending tags appear as Empty elements (elements without data) can appear as XML elements MUST have an ending tag A starting and ending tag (along with any text) makes up an element

6 Slide 6 Elements (Nesting) Elements can be nested These are hierarchical nodes Elements MUST be nested correctly though A child element must completely reside in its parent element There must be exactly one and only one root element

7 Slide 7 Elements (Nesting – Example) 42 Root element is Nested element is

8 Slide 8 XML Attributes (Introduction) Elements can have one or more attributes Same rules as HTML Attributes appear after the starting tag name One element cannot have two attributes of the same name One element can have many attributes though

9 Slide 9 XML Attributes (Syntax 1) Attributes appear as key=value pairs An attribute must have both a key and a value Attribute keys do not appear in quotation marks Attribute values must appear in quotation marks Remember, single and double quotes are interchangeable A space separates each key=value pair Attributes can appear in starting and empty element tags but cannot appear in an ending tag For a given element, each attribute key must differ

10 Slide 10 XML Attributes (Example) In the following example, id and size are attributes of the element 42

11 Slide 11 Comparing Attributes and Elements The following 2 documents are (roughly) equivalent Bill 12345 Bill

12 PART 2 XML Namespaces

13 Slide 13 Namespace Caveats XML namespaces are the source of criticism and confusion XML namespaces are the source of many myths.NET namespaces and XML namespaces are not the same thing In fact, they have nothing to do with each other

14 Slide 14 The Problem of Name Ambiguity Names can be ambiguous When we say “Las Vegas” do we mean “Las Vegas, Nevada” or “Las Vegas, New Mexico” How many cities have the name “Springfield”? When we say address, do we mean street address or Internet address Name ambiguity occurs when two XML documents have elements of the same name but with different meanings (context)

15 Slide 15 The Problem of Name Ambiguity (Example) 123 Oak street 121.216.39.3 The meaning of differs between the two contexts

16 Slide 16 The Purpose of XML Namespaces (1) They eliminate name ambiguity in element names between documents Namespaces answer the question “Are we talking about the same thing?” XML namespaces were released about 1 year after XML itself was released

17 Slide 17 The Purpose of Namespaces (2) According to the W3C namespace specification: We envision applications of Extensible Markup Language (XML) where a single XML document may contain elements and attributes (here referred to as a "markup vocabulary") that are defined for and used by multiple software modules.

18 Slide 18 Implementation of XML Namespaces XML namespaces use URIs (IRIs) to qualify element names This allows us to use the same element name with a different URI thereby qualifying the element name The URI is just a globally unique name Formally, XML namespaces define a vocabulary or universe of names

19 Slide 19 The Implementation of Namespaces (1) Namespace names are defined through ‘special’ attributes Any attribute starting with the prefix xmlns: is considered a prefix defining attribute The prefix following the attribute is the local abbreviation for the namespace The prefix name has no relevance although there are common naming conventions The attribute value is a unique URI

20 Slide 20 XML Namespace Example (Android) The prefix android is given to http://schemas.android.com/apk/res/android http://schemas.android.com/apk/res/android The prefix tools is given to http://schemas.android.com/tools http://schemas.android.com/tools

21 Slide 21 Namespaces (Quotable Quotes) What Does a Namespace URL Locate? There is nothing at all at the end of a namespace URI, except perhaps a 404 Not Found error

22 Slide 22 Namespaces (Myths) IT’S NOT NECESSARILY A WEB SITE IT’S NOT A REFERENCE TO A PROGRAM ON THE WEB IT’S NOT A POINTER TO A RESOURCE IT’S JUST A NAME

23 Slide 23 Applications using XML namespaces XML namespaces are widely used in The Schema Definition Language (XSDL) The Extensible Stylesheet Language (XSL) The can represent a vocabulary

24 Slide 24 Characteristics of Namespace URIs (Example) The following URIs ARE different: http://www.example.org/foo http://www.Example.org/foo http://www.example.org/Foo And so are the following: http://www.example.org/~foo http://www.example.org/%7efoo


Download ppt "PART 1 XML Basics. Slide 2 Why XML Here? You need to understand the basics of XML to do much with Android All of they layout and configuration files are."

Similar presentations


Ads by Google