1 / 18

Introduction to XML

Introduction to XML. XML – Extensible Markup Language. Outline. XML Overview XML Components DTD – Document type definition. 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

ira
Download Presentation

Introduction to XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 <Car> Chevrolet Corvette </Car> • 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 <Car> <Identification> <Make>Chevrolet</Make> <Model>Corvette</Model> <VIN>123</VIN> </Identification> <Engine> <Displacement>6.2</Displacement> <Cylinders>8</Cylinders> </Engine> </Car>

  8. XML Components • Root element • Only element in document with no parent • Each document can have only 1 root element • Invalid document: <car>…</car> <boat>…</boat>

  9. XML Components • Attributes • Name-value pair(s) assigned to tag • Identification element has 2 attributes and 1 child <Car> <Identification Make=“Chevrolet” Model=“Corvette”> <VIN>123</VIN> </Identification> </Car>

  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 <!-- This is a comment --> • Comments CAN NOT appear: • Inside a tag • Inside another comment

  12. XML Components • XML Declaration (the following is used in Android): <?XML version=“1.0” encoding=“UTF-8”?> • 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 <!ELEMENT Car (Identification, Engine)> <!ELEMENT Identification (Make, Model, VIN)> <!ELEMENT Make (#PCDATA)> <!ELEMENT Model (#PCDATA)> <!ELEMENT VIN (#PCDATA)> <!ELEMENT Engine (Displacement, Cylinders)> <!ELEMENT Displacement (#PCDATA)> <!ELEMENT Cylinders (#PCDATA)>

  16. DTD – Element specifications

  17. DTD – Specifications example • Example <!ELEMENT Student (Identification, GradYear)> <!ELEMENT Identification (Name, Town?, Job*)> <!ELEMENT Name (#PCDATA)> <!ELEMENT Town (#PCDATA)> <!ELEMENT Job (#PCDATA)>

  18. Full example • On public drive • Example • Car.xml with embedded DTD • Car.xml with separate DTD file

More Related