Download presentation
Presentation is loading. Please wait.
Published byHillary Miller Modified over 9 years ago
1
Introduction to XML XML – Extensible Markup Language
2
Outline XML Overview XML Components DTD – Document type definition
3
XML Overview Resources – WWW consortium (W3C) Home page on XML http://www.w3.org/XML – XML 1.0 Spec http://www.w3.org/TR/REC-xml/ – O’Reilly publishing XML resources http://www.xml.com
4
XML Overview What is the connection between XML and Android? – Manifest File Register activities Required permissions Other aspects of the application – Developing Activities Declarative – XML – Google’s preferred method » Code is more concise » Less likely to change Visual Editor (generates XML) – editor still unwieldy Procedural – within Java Code
5
XML Overview XML represents the contents of data – not presentation To incorporate presentation, style sheets can be used
6
XML Components XML elements and tags Chevrolet Corvette – In this example: One element: Car Car element starts and ends with tags XML is case–sensitive (unlike HTML)
7
XML Components Parents, children, and siblings Chevrolet Corvette 123 6.2 8
8
XML Components Root element – Only element in document with no parent – Each document can have only 1 root element – Invalid document: …
9
XML Components Attributes – Name-value pair(s) assigned to tag – Identification element has 2 attributes and 1 child 123
10
XML Components When to use attributes and when to use children? – Attributes are for metadata of element – Children are for information about element Subject of heated debate – No clear way to tell what is metadata and what is information Android – both used in specific instances
11
XML Components Comments – Same as in HTML – Comments CAN NOT appear: Inside a tag Inside another comment
12
XML Components XML Declaration (the following is used in Android): Version is the version of XML being used – 1.0 is current version Encoding is the type of text – UTF-8 is default Variable width: 1 – 4 bytes Superset of ASCII – Others ASCII, UTF-16, others
13
XML Components Checking for well-formedness – Start tags must have matching end tags – Elements may nest, but not overlap – There must be exactly one root element – Attribute values must be quoted – An element cannot have two same-named attributes – Comments cannot be inside tags
14
DTD – Document type definitions Written in formal syntax Allow for describing: – What elements may appear – What elements’ contents and attributes are Usually stored in separate file –.dtd extension is typical – Information can be contained in associated.xml file
15
DTD – Document type definitions Example
16
DTD – Element specifications SymbolMeaning no symbolelement must appear exactly once ?optional but if used, must appear exactly once *element appears zero or more times +element must appear at least once |choice of elements – but only one can be used,sequence of elements that can be used (each element used according to its symbol)
17
DTD – Specifications example Example
18
Full example On public drive – Example Car.xml with embedded DTD Car.xml with separate DTD file
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.