24
XML Technologies XML Basics What is XML? Why use XML? How to write XML? 1 XML Technologies - 2012 - David Raponi

XML Technologies

  • Upload
    halima

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

XML Technologies. XML Basics What is XML? Why use XML? How to write XML?. Week 1: XML Basics > 1. What is XML?. 1. What is XML?. e X tensible Markup Language Markup: text + annotations This is a sentence. Extensible: A language for creating new markup languages - PowerPoint PPT Presentation

Citation preview

Page 1: XML Technologies

XML Technologies

• XML Basics What is XML? Why use XML? How to write XML?

1XML Technologies - 2012 - David Raponi

Page 2: XML Technologies

2XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 1. What is XML?

1. What is XML?

eXtensible Markup Language• Markup:

text + annotations <p>This is a sentence.</p>

• Extensible: A language for creating new markup languages <myTag>I can make up anything</myTag>

Page 3: XML Technologies

3XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 1. What is XML?

An example:

<?xml version=“1.0” encoding=“utf-8”?><family>

<parents><parent gender=“male”>Romolo</parent><parent gender=“female”>Silvia</parent>

</parents><children>

<child gender=“male”>David</child></children>

</family>

Page 4: XML Technologies

4XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 1. What is XML?

What it is and what it isn’t…

• It is self-descriptive (commonsense tag names)• Focuses on STORING and DEFINING data• Focuses also on ORGANIZING data for easy

manipulation• It does not handle displaying of data… that’s

HTML’s job• It is not a processing “code” of any kind• It is not a version of XHTML

Page 5: XML Technologies

5XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 1. What is XML?

Advantages of XML

• Easily read by humans• Simple and lightweight• Bridges a gab between simple lists and overkill

databases• Platform independent• Lots of technologies exist to work with XML• Anal-retentively dependable!

Page 6: XML Technologies

6XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 1. What is XML?

Markup and so much more…

To Summarize, XML is:- a markup language that allows for simple

and contextual storage of data that can be easily read and manipulated.

- but on its own, it doesn’t actually DO anything. It’s just a bunch of information, like a grocery list.

Page 7: XML Technologies

7XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 1. What is XML?

Markup and so much more…

Another amazing aspect:XML can be used to create new markup languages

This is because the tags are named however you wish, and then “definitions” (next week) can be made for those new tags.

Page 8: XML Technologies

8XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 1. What is XML?

Example revisited: What do we notice?

<?xml version=“1.0” encoding=“utf-8”?><family>

<parents><parent gender=“male”>Romolo</parent><parent gender=“female”>Silvia</parent>

</parents><children>

<child gender=“male”>David</child></children>

</family>

Page 9: XML Technologies

9XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 1. What is XML?

Initial observations:

1. Requires an initial declaration• <?xml version=“1.0” encoding=“utf-8”?>

2. Made up of elements (open + close tags)3. Tags may contain attributes4. There is a nesting structure5. Can can create your own elements (only a very

few naming restrictions apply)

Page 10: XML Technologies

10XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 1. What is XML?

A quick comparison:<?xml version=“1.0” encoding=“utf-8”?><family>

<males><person role=“father”>Romolo</person ><person role=“child”>David</person >

</males><females>

<person role=“mother”>Silvia</person ></females>

</family>Q: Is it all the same? Does it matter? Is there another way to write it out?

Page 11: XML Technologies

11XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 2. Why use XML?

2. Why use XML?

Since XML is…• Lightweight• Self-definable• Platform independent• Great for organizing information

… we can…

Page 12: XML Technologies

12XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 2. Why use XML?

What can you do with XML?

1. Create Twitter feeds2. Probably everything on Facebook3. Make scalable graphics (vector images)4. Run an entire website (no HTML files!)5. Host fun XML parties… ?6. Program Documents (get ready to have

your minds blown…)7. Transfer data quickly (webservices)

Page 13: XML Technologies

13XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 2. Why use XML?

What can you do with XML?

8. Keep data and design separate (quick and simplified updates!)

9. Quick storage of data (mini-database)10.Sending out and reading in info (RSS, podasts)11.Quick referencing (saving settings)12.Smaller scale CMSs13.Blogs

Page 14: XML Technologies

14XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 2. Why use XML?

When NOT to use XML?

1. When a dedicated database is warranted2. When display is most important factor3. Basically whenever another technology can

get the job done faster.

Page 15: XML Technologies

15XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 2. Why use XML?

When NOT to use XML?

Please note: you will not use every technology you learn in this program on a daily basis. It very much depends on your future career.

Making simple sites? Not much XML involved.Working for dedicated web services, data industries (banks, hospitals, etc) or in IT? Lots of XML!

Page 16: XML Technologies

16XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 3. How to write XML?

3. How to write XML

1. Declaration and root2. Reserved words3. Special characters4. Elements and attributes5. Nesting6. Must be “Well-Formed”

Page 17: XML Technologies

17XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 3. How to write XML?

Declaration1. Declaration and the root2. Reserved words3. Special characters4. Elements and attributes5. Nesting6. Must be “Well-Formed”

Each XML document must begin with a declaration. This tells the program (in our case, the browser) to interpret it as XML

<?xml version=“1.0”?> (no closing tag!)

Options include:• encoding=“utf-8” (or “ISO-8859-1”)• standalone=“yes” (or “no”)

o Yes: the DTD is located internallyo No: the DTD is external (default)

Page 18: XML Technologies

18XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 3. How to write XML?

Declaration1. Declaration and the root2. Reserved words3. Special characters4. Elements and attributes5. Nesting6. Must be “Well-Formed”

Each XML document must also have a root element within which everything else is found.

<?xml version=“1.0”?><elementName>…</elementName

Page 19: XML Technologies

19XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 3. How to write XML?

3. How to write XML1. Declaration and the root2. Reserved words3. Special characters4. Elements and attributes5. Nesting6. Must be “Well-Formed”

There are no reserved words in XML!

However, you cannot:• Begin with a number• Begin with punctuation• Have any spaces• Begin with “xml”

• Good: <fish>• Bad: <2fish> <a fish> <?fish> <xmlFish>

Page 20: XML Technologies

20XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 3. How to write XML?

3. How to write XML1. Declaration and the root2. Reserved words3. Special characters4. Elements and attributes5. Nesting6. Must be “Well-Formed”

There are a few characters that should be replaced as follows:

& &amp;< &lt;> &gt;‘ &apos;“ &quote; (except for in attributes)

I’m already lying to you: only the first two (& and <) are strict no-nos. Everything else is “good practice” to make life easier.

Page 21: XML Technologies

21XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 3. How to write XML?

3. How to write XML1. Declaration and the root2. Reserved words3. Special characters4. Elements and attributes5. Nesting6. Must be “Well-Formed”

An element consists of an opening and closing tag (like in HTML) of the same case.

An element can contain any number of attributes with values wrapped in matching quotes.

Good: <tag attribute=“something”></tag>Bad: <tag attribute=“something’></Tag>

Note: whenever possible, avoid attributes. They should be reserved for “metadata”.

Page 22: XML Technologies

22XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 3. How to write XML?

3. How to write XML1. Declaration and the root2. Reserved words3. Special characters4. Elements and attributes5. Nesting6. Must be “Well-Formed”

Open and close tags as you would in HTML, that is: In the proper order.

<section><title>My Title</section></title>This causes kittens to explode

<section><title>My Title</title></section> Kittens live another day

Page 23: XML Technologies

23XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 3. How to write XML?

3. How to write XML1. Declaration and the root2. Reserved words3. Special characters4. Elements and attributes5. Nesting6. Must be “Well-Formed”

To be well-formed, XML must PHYSICALLY be written correctly. It may or may not live up to the pre-determined requirements (it will not validate), but it is at least an honest and true XML document:• Must include initial declaration• Must have a root element that captures

everything else• All tags must be closed• All attribute values must be in quotes• No illegal characters present• No illegally named elements

Page 24: XML Technologies

24XML Technologies - 2012 - David Raponi

Week 1: XML Basics > 3. How to write XML?

Final remarksRemember, XML doesn’t just store data, it organizes it. The organizational approach of an XML document should be carefully considered since the structure itself can also be thought of as data.

<course>HTML</course><course>JS 1</course><course>JS 2</course><course>CSS</course><course>PHP</course>

<semester><course>HTML</

course><course>JS 1</course>

</semester><semester>

<course>JS 2</course><course>CSS</course><course>PHP</course>

</semester>Technically, the data is the same, but the 2nd structure reveals more information!