Top Banner
EXTENSIBLE MARKUP LANGUAGE (XML) 1
34

Xml

Jul 31, 2015

Download

Education

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Xml

1

EXTENSIBLE

MARKUP

LANGUAGE

(XML)

Page 2: Xml

2

WHAT IS XML?

eXtensible Markup Language markup language for documents containing

structured information much like HTML XML was designed to carry data, not to display

data XML tags are not predefined. You must define

your own tags Based on Standard Generalized Markup

Language (SGML) Version 1.0 introduced by World Wide Web

Consortium (W3C) in 1998 Bridge for data exchange on the Web

Page 3: Xml

3

WHAT IS XML? a method for putting structured data into a text

file; these files are:Easy to readUnambiguousExtensiblesoftware- and hardware-independent tool for

carrying information.self-descriptive

Page 4: Xml

4

WHAT IS XML?

XML is Not a Replacement for HTML In most web applications, XML is used to transport

data, while HTML is used to format and display the data.

Page 5: Xml

5

HOW CAN XML BE USED?

XML Separates Data from HTML XML Simplifies Data Sharing XML Simplifies Data Transport XML Simplifies Platform Changes XML Makes Your Data More Available XML is Used to Create New Internet Languages

XHTML  WSDL for describing available web services WAP and WML as markup languages for handheld

devices RSS languages for news feeds

Page 6: Xml

6

If Developers Have Sense

If they DO have sense, future applications will exchange their data in XML.

Page 7: Xml

7

COMPARISONS

Extensible set of tags Content orientated Allows multiple output

forms

Fixed set of tags Presentation oriented Single presentation

XML HTML

Page 8: Xml

8

AUTHORING XML ELEMENTS An XML element is made up of a start tag, an

end tag, and data in between. Example: <director> Matthew Dunn </director> Example of another element with the same

value: <actor> Matthew Dunn </actor> XML tags are case-sensitive: <CITY> <City> <city> XML can abbreviate empty elements, for

example: <married> </married> can be abbreviated to <married/>

Page 9: Xml

9

AUTHORING XML DOCUMENTS

A basic XML document is an XML element that can, but might not, include nested XML elements.

Example: <books> <book isbn=“123”> <title> Second Chance </title> <author> Matthew Dunn

</author> </book> </books>

Page 10: Xml

10

XML DATA MODEL: EXAMPLE

<BOOKS><book id=“123”

loc=“library”> <author>Hull</author> <title>California</title> <year> 1995 </year></book><article id=“555”

ref=“123”> <author>Su</author> <title> Purdue</title></article></BOOKS> Hull Purdue

BOOKS

123 555

California

Su

titleauthor

title

author

articlebook

year

1995

ref

loc=“library”

Page 11: Xml

11

XML EXAMPLE<?xml version="1.0" encoding="ISO-

8859-1"?><note>  <to>Tove</to>  <from>Jani</from>  <heading>Reminder</heading>  <body>Don't forget me this weekend!</body></note>

Page 12: Xml

12

XML SYNTAX RULES All XML Elements Must Have a Closing

TagIn HTML, some elements do not have to have a closing tag: <p>This is a paragraph

<p>This is another paragraph In XML, it is illegal to omit the closing tag. All elements must have a closing tag:

<p>This is a paragraph</p><p>This is another paragraph</p>

Page 13: Xml

13

XML SYNTAX RULES XML Tags are Case Sensitive

XML tags are case sensitive. The tag <Letter> is different from the tag <letter>.

Opening and closing tags must be written with the same case:<Message>This is incorrect</message><message>This is correct</message>

Page 14: Xml

14

XML SYNTAX RULES XML Elements Must be Properly Nested

In HTML, you might see improperly nested elements:<b><i>This text is bold and italic</b></i> In XML, all elements must be properly nested within each other:<b><i>This text is bold and italic</i></b>

Page 15: Xml

15

XML SYNTAX RULES XML Documents Must Have a Root

ElementXML documents must contain one element that is the parent of all other elements. This element is called the root element.<root>  <child>    <subchild>.....</subchild>  </child></root>

Page 16: Xml

16

XML SYNTAX RULES XML Attribute Values Must be Quoted XML elements can have attributes in name/value

pairs just like in HTML. In XML, the attribute values must always be quoted. Incorrect:

<note date=12/11/2007>  <to>Tove</to>  <from>Jani</from></note>

Correct:<note date="12/11/2007">  <to>Tove</to>  <from>Jani</from></note>

Page 17: Xml

17

XML SYNTAX RULES : ENTITY REFERENCES

special meaning of Some characters in XML. Error in XML:

<message>if salary < 1000 then</message> To avoid this error, replace the "<" character with an

entity reference: <message>if salary &lt; 1000 then</message>

There are 5 predefined entity references in XML: &lt; < less than &gt; > greater than &amp; & ampersand  &apos; ' apostrophe &quot; " quotation mark

Note: Only the characters "<" and "&" are strictly illegal in XML. The greater than character is legal, but it is a good habit to replace it.

Page 18: Xml

18

Comments in XML The syntax for writing comments in XML is similar

to that of HTML.<!-- This is a comment -->

XML Syntax Rules

Page 19: Xml

19

White-space is Preserved in XML HTML truncates multiple white-space characters

to one single white-space: HTML: Hello           Tove Output: Hello Tove

XML: the white-space in a document is not truncated.

Hello           Tove Output: Hello           Tove

XML Syntax Rules

Page 20: Xml

20

XML Stores New Line as LF Windows applications : a new line -> carriage

return (CR) and line feed (LF). Unix applications : a new line -> LF character Macintosh applications : a new line -> LF

character XML stores a new line as LF.

XML Syntax Rules

Page 21: Xml

21

A Well Formed

XML document

Page 22: Xml

22

XML DECLARATION

The XML declaration looks like this:<?xml version="1.0" encoding="UTF-8" standalone="yes"?> The XML declaration is not required by browsers, but is

required by most XML processors (so include it!) If present, the XML declaration must be first--not even

whitespace should precede it Note that the brackets are <? and ?> version="1.0" is required (this is the only version so far) encoding can be "UTF-8" (ASCII) or "UTF-16" (Unicode),

or something else, or it can be omitted standalone tells whether there is a separate DTD

Page 23: Xml

23

An element can contain: other elements text attributes or a mix of all of the above...

XML Elements

Page 24: Xml

24

<bookstore>  <book category="CHILDREN">    <title>Harry Potter</title>    <author>J K. Rowling</author>    <year>2005</year>    <price>29.99</price>  </book>  <book category="WEB">    <title>Learning XML</title>    <author>Erik T. Ray</author>    <year>2003</year>    <price>39.95</price>  </book></bookstore>

XML Elements

Page 25: Xml

25

XML elements must follow these naming rules: Names can contain letters, numbers, and other

characters Names cannot start with a number or punctuation

character Names cannot start with the letters xml (or XML, or

Xml, etc) Names cannot contain spaces

XML Elements Naming Rules

Page 26: Xml

26

<person sex="female">  <firstname>Anna</firstname>  <lastname>Smith</lastname></person> <person>  <sex>female</sex>  <firstname>Anna</firstname>  <lastname>Smith</lastname></person>

XML Elements vs. Attributes

Page 27: Xml

27

1) <note date="10/01/2008">  <to>Tove</to>  <from>Jani</from>  <heading>Reminder</heading>  <body>Don't forget me this weekend!</body></note>

XML Elements vs. Attributes

Page 28: Xml

28

2) <note>  <date>10/01/2008</date>  <to>Tove</to>  <from>Jani</from>  <heading>Reminder</heading>  <body>Don't forget me this weekend!</body></note>

XML Elements vs. Attributes

Page 29: Xml

29

3) <note>  <date>    <day>10</day>    <month>01</month>    <year>2008</year>  </date>  <to>Tove</to>  <from>Jani</from>  <heading>Reminder</heading>  <body>Don't forget me this weekend!</body></note>

XML Elements vs. Attributes

Page 30: Xml

30

Some of the problems with using attributes are: attributes cannot contain multiple values (elements

can) attributes cannot contain tree structures (elements

can) attributes are not easily expandable (for future

changes) Attributes are difficult to read and maintain. Use

elements for data. Use attributes for information that is not relevant to the data.

Avoid XML Attributes?

Page 31: Xml

31

XML Validation

Page 32: Xml

32

XML with correct syntax is "Well Formed" XML.

XML validated against a DTD or XMLSchema is "Valid" XML.

XML Validation

Page 33: Xml

33

Page 34: Xml

34