1. Trang chủ
  2. » Luận Văn - Báo Cáo

Lecture E-Commerce - Chapter 19: eXtensible Markup Language (XML) (part II)

45 80 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 45
Dung lượng 276,76 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Lecture E-Commerce - Chapter 19: eXtensible Markup Language (XML) (part II). In this chapter students will be able to: XML elements are extensible, XML attributes, XML namespaces, XML encoding, viewing XML files.

Trang 1

CSC 330 E-Commerce

Teacher

Ahmed Mumtaz Mustehsan

GM-IT CIIT Islamabad

COMSATS Institute of Information Technology

T2-Lecture-4

Trang 2

eXtensible Markup Language (XML)

Part - II

For Lecture Material/Slides Thanks to: www.w3schools.com

Trang 4

XML Elements are Extensible

 XML elements can be extended to carry more information.

 Look at the following XML example:

Trang 5

XML Elements are Extensible…

 Imagine that the author of the XML document added some extra information to it:

 Should the application break or crash?

 No The application should still be able to find the <to>,

<from>, and <body> elements in the XML document and produce the same output.

 One of the beauty of XML, is that it can be extended

Message To: Mumtaz From: Tariq Don't forget to attend party on weekend!

Trang 6

XML Attributes

Trang 7

<file type="gif">computer.gif</file>

important to the software that wants to manipulate the element:

Trang 8

XML Attributes Must be Quoted

single or double quotes can be used

Trang 9

XML Attributes Must be Quoted

can use single quotes

Example:

<University head = ‘ Rector “COMSATS" Institute'>

or you can use character entities:

<University head = ‘ Rector &quot;COMSATS&quot; Institute'>

Trang 10

XML Elements vs Attributes

Example-1:

<person sex="female“ >

<firstname> Amna </firstname>

<lastname> Atif </lastname>

Trang 11

XML Elements vs Attributes…

In Example-1, sex is an attribute

In Example-2, sex is an element

attributes or when to use elements,

However:

Recommendations are:

Trang 12

XML: Different ways to define information

presented in different ways

Trang 13

XML: Different ways to define information.

Trang 14

XML: Different ways to define information.

Trang 15

Avoid XML Attributes?

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

Recommendations:

 Use elements for data

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

 Don't end up like this:

◦ <note day="10" month="01" year="2008"

to="Tove" from="Jani" heading="Reminder"

body="Don't forget me this weekend!">

</note>

Trang 16

XML Attributes for Metadata

 Sometimes ID references are assigned to elements.

 These IDs can be used to identify XML elements the same way as the id attribute in HTML

Trang 17

XML Attributes for Metadata…

notes

Recommendations:

Metadata (data about data) should be stored as

attributes, and the data itself should be stored as

elements

Trang 18

XML Namespaces

Trang 19

Before we Begin: a review of URI

Uniform Resource Identifier (URI) :

characters which identifies an Internet Resource

Locator (URL) which identifies an Internet domain

address

Resource Name (URN)

In our examples we will only use URLs

Trang 20

XML Namespaces

This often results in a conflict when trying to mix XML documents from different XML applications

Trang 21

would be a name conflict Both contain a <table>

element, but the elements have different content and

meaning

A user or an XML application will not know how to

Trang 22

Solving the Name Conflict Using a Prefix

 Name conflicts in XML can easily be avoided using a name

 In the example above, there will be no conflict because the two

<table> elements have different names But are we allowed to use prefix with a : ?

Trang 23

XML Namespaces : The xmlns Attribute

When using prefixes in XML

start tag of an element

Example

<h:table xmlns:h="http://www.w3.org/TR/html4/">

Trang 24

XML Namespaces - The xmlns Attribute

The namespace declaration as an attribute can be defined:

Example-1: each attribute is defined with separate xmsns

Trang 25

XML Namespaces - The xmlns Attribute…

The namespace declaration as an attribute can be defined:

Example-1: each attribute is defined with combined xmsns defination

The purpose is to give the namespace a unique name However, often

companies use the namespace as a pointer to a web page containing

Trang 26

Default Namespaces

 Defining a default namespace for an element saves us from using prefixes in all the child elements It has the following syntax:

<width>80</width>

<length>120</length>

</table>

Trang 27

XML Encoding

Trang 28

XML Encoding

like Norwegian æøå, or French êèé

or save the XML files as UTF-8

for each different character used in a document

called character set, character map, code set, and code page

Trang 29

of text documents

by a name and a number

Unicode has two variants: UTF-8 and UTF-16

commonly used characters and two (or three) bytes for the rest

and three bytes for the rest

Trang 30

UTF-8 - The Web Standard

HTML-5, CSS, JavaScript, PHP, SQL, and XML

Trang 31

 The XML standard states that all XML software must

understand both UTF-8 and UTF-16.

 UTF-8 is the default for documents without encoding

information.

 In addition, most XML software systems understand

encodings like ISO-8859-1 , Windows-1252, and ASCII

Trang 32

XML Errors

Most often,

three computers, the browser might display

meaningless text, or you might get an error message

Example:

“This XML file does not appear to have any style

information associated with it.”

Trang 33

When you write an XML document:

standard

Trang 34

Viewing XML Files

Trang 35

Viewing XML Files

 Raw XML files can be viewed in all major browsers.

 Don't expect XML files to be displayed as HTML pages.

elements can be clicked to expand or collapse the element

structure To view the raw XML source (without the + and -

signs), select "View Page Source" or "View Source" from the browser menu.

raw XML, you must right click the page and select "View Source"

Trang 36

Viewing an Invalid XML File

browsers might report the error, some may display

it incorrectly

Trang 37

Why Does XML Display Like This?

to display the data

XML document, browsers do not know if a tag like

<table> describes an HTML table or a dining table

data, most browsers will just display the XML

document as it is

Trang 38

The second line links the XML file to the CSS file:

Trang 39

It is possible to use CSS to format an XML document.

to format an XML document:

The CD catalog formatted with the CSS file

Displaying your XML Files with CSS

Trang 41

Displaying XML with XSLT

Transformations) is the recommended style sheet language for XML

elements to hide and display, etc

document

XML - XSLT

Trang 42

XPath is Used in XSLT

 XPath is a syntax for defining parts of an XML document

 XPath uses path expressions to navigate in XML documents

 XPath contains a library of standard functions

 XPath is a major element in XSLT

 XPath is also used in XQuery, XPointer and XLink

XML - Xpath

Trang 43

XLink is used to create hyperlinks within XML

documents

link

links (for linking multiple resources together)

files

XML - XLink

Trang 44

XPointer allows the links to point to specific parts of

Trang 45

The End XML Part-II

T2-Lecture-4 Thank You

Ngày đăng: 18/01/2020, 18:27