XML Introduction1

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 31

Introduction to

XML
Engr. Michael Marasigan Fernandez
Contents
List of topics to discuss in this session:
1. Static vs Dynamic Website
2. What is XML
3. Difference between XML and HTML
4. XML Does not use predefined tags
5. XML is Extensible
6. XML simplifies things
7. Define W3C and its importance

Assignment 1
2
STATIC vs
DYNAMIC

3
Static Website
is made up of webpages created using
HTML, CSS and Javascript (all examples
of web development languages).

Edit and changes of the design is edited at


a code level to the original HTML file and
reflected to your webpage instantly.

Static site is that every user receives


and views the exact same content.

4
Example of Static Website
1. resume websites

2. portfolio websites

3. brochure websites

4. one-off landing pages

5. and other informational or read-only sites

5
Example of Static Website

6
Example of Static Website

https://www.redpaperplane.com/

7
Example of Static Website

8
Dynamic Web site
dynamic websites allow for the content of each
page to be delivered and displayed dynamically,
or on-the-fly, according to user behavior or from
user-generated content.

gives you the ability to customize and


personalize the website experience, and
what is displayed, for a specific user..

allows you to make changes to many pages


at the same time, since modifications made
to one dynamic page can be automatically
made across thousands.
9
Example of Dynamic Web Site
1. Instagram: as a social media site, dependent on user-
generated content, Instagram relies on a dynamic
website.

2. CNN: media outlets use dynamic websites to update


their content, either in response to breaking news or as
stories age.

3. Disney Plus: as a large streaming site, this dynamic


entertainment website's dynamic nature allows its
content to be chosen and displayed according to a user's
location, subscription and preferences.

10
Example of Dynamic Website

11
Example of Dynamic Website

12
Example of Dynamic Website

13
Introduction
to XML
What is XML
- stands for eXtensible Markup Language

- is a software- and hardware-independent


tool for storing and transporting data.
- Designed to be self-descriptive. users must
define their own tags for their specific
application before using them.

15
XML Example Coding
16
Difference Between XML and HTML
XML HTML
The full form is eXtensible Markup The full form is Hypertext Markup
Language Language

The main purpose is to focus on the Focusses on the appearance of data.


transport of data and saving the data Enhances the appearance of text

XML is dynamic because it is used in HTML is static because its main function
the transport of data is in the display of data
It is case-sensitive. The upper and
It is not case-sensitive. Upper and lower
lower case needs to be kept in mind
case are of not much importance in HTML
while coding
You can define tags as per your
It has its own pre-defined tags, and it is
requirement, but closing tags are
not necessary to have closing tags
mandatory

17
Difference Between XML and HTML
XML HTML

XML can preserve white spaces White spaces are not preserved in HTML

eXtensible Markup Language is content- Hypertext Markup Language, on the


driven, and not many formatting features other hand, is presentation driven. How
are available the text appears is of utmost importance

Any error in the code shall not give the Small errors in the coding can be ignored
final outcome and the outcome can be achieved

No lengthy documents. Only the syntax


The size of the document may be large needs to be added for best-formatted
output

18
19
The XML Tree Structure

20
The XML Tree Structure

21
XML Tree Structure
Prolog
The XML prolog is optional. If it exists, it must
come first in the document.

root element
An XML tree starts at a root element

Parent element/s
branches from the root to parent
elements
Child element/s
All elements can have sub elements (child
elements)
- The terms parent, child, and sibling are used to describe the
relationships between elements.
- Parents have children. Children have parents. Siblings are
children on the same level (brothers and sisters).
- All elements can have text content (Harry Potter) and
attributes (category="cooking"). 22
XML Declaration
The XML document can optionally have an XML declaration. It is written as follows

Where version is the XML version and encoding specifies the character encoding used in the
document.

Syntax Rules for XML Declaration


• The XML declaration is case sensitive and must begin with "<?xml>" where "xml" is written in
lower-case.
• If document contains XML declaration, then it strictly needs to be the first statement of the XML
document.
• The XML declaration strictly needs be the first statement in the XML document.
• An HTTP protocol can override the value of encoding that you put in the XML declaration.
XML Attributes
An attribute specifies a single property for the element, using a name/value pair. An XML-
element can have one or more attributes. For example −

<a href = "http://www.rtu.edu.ph/">RTU Website</a>

Here href is the attribute name and http://www.rtu.edu.ph/ is attribute value.

Syntax Rules for XML Attributes


• Attribute names in XML (unlike HTML) are case sensitive. That is, HREF and href are considered
two different XML attributes.
• Same attribute cannot have two values in a syntax. The following example shows incorrect syntax
because the attribute b is specified twice

<a b = "x" c = "y" b = "z">....</a>


XML Text
The names of XML-elements and XML-attributes are case-sensitive, which means the name
of start and end elements need to be written in the same case. To avoid character encoding
problems, all XML files should be saved as Unicode UTF-8 or UTF-16 files.

Whitespace characters like blanks, tabs and line-breaks between XML-elements and
between the XML-attributes will be ignored.
Some characters are reserved by the XML syntax itself. Hence, they cannot be used directly. To use
them, some replacement-entities are used, which are listed below −

Not Allowed Character Replacement Entity Character Description

< &lt; less than

> &gt; greater than

& &amp; ampersand

' &apos; apostrophe

" &quot; quotation mark


XML - Declaration
XML declaration contains details that prepare an XML processor to parse the XML
document. It is optional, but when used, it must appear in the first line of the XML
document.
Each parameter consists of a parameter name, an equals sign (=), and parameter value inside
a quote. Following table shows the above syntax in detail −
Parameter Parameter_value Parameter_description

Version 1.0 Specifies the version of the XML standard


used.

Encoding UTF-8, UTF-16, ISO-10646-UCS-2, ISO- It defines the character encoding used in
10646-UCS-4, ISO-8859-1 to ISO-8859-9, the document. UTF-8 is the default
ISO-2022-JP, Shift_JIS, EUC-JP encoding used.

Standalone yes or no It informs the parser whether the document


relies on the information from an external
source, such as external document type
definition (DTD), for its content. The default
value is set to no. Setting it to yes tells the
processor there are no external
declarations required for parsing the
document.
XML - Declaration
Rules
An XML declaration should abide with the following rules −
• If the XML declaration is present in the XML, it must be placed as the first line in the XML
document.
• If the XML declaration is included, it must contain version number attribute.
• The Parameter names and values are case-sensitive.
• The names are always in lower case.
• The order of placing the parameters is important. The correct order is: version, encoding and
standalone.
• Either single or double quotes may be used.
• The XML declaration has no closing tag i.e. </?xml>
XML - Declaration
XML Declaration Examples
Following are few examples of XML declarations −
XML declaration with no parameters −
<?xml >

XML declaration with version definition −


<?xml version = "1.0">

XML declaration with all parameters defined −


<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>

XML declaration with all parameters defined in single quotes −


<?xml version = '1.0' encoding = 'iso-8859-1' standalone = 'no' ?>
XML - Elements
XML elements can be defined as building blocks of an XML. Elements can behave as containers
to hold text, elements, attributes, media objects or all of these.
Each XML document contains one or more elements, the scope of which are either delimited by
start and end tags, or for empty elements, by an empty-element tag.

Syntax
Following is the syntax to write an XML element −
<element-name attribute1 attribute2> ....content </element-name>

where,
• element-name is the name of the element. The name its case in the start and end tags must match.
• attribute1, attribute2 are attributes of the element separated by white spaces. An attribute defines a
property of the element. It associates a name with a value, which is a string of characters. An attribute is
written as −

name = "value"
name is followed by an = sign and a string value inside double(" ") or single(' ') quotes.
XML - Elements
XML Elements Rules

Following rules are required to be followed for XML elements −

• An element name can contain any alphanumeric characters. The only punctuation mark allowed in

names are the hyphen (-), under-score (_) and period (.).

• Names are case sensitive. For example, Address, address, and ADDRESS are different names.

• Start and end tags of an element must be identical.

• An element, which is a container, can contain text or elements as seen in the above example.
XML - Elements
XML Elements Rules

Following rules are required to be followed for XML elements −

• An element name can contain any alphanumeric characters. The only punctuation mark allowed in

names are the hyphen (-), under-score (_) and period (.).

• Names are case sensitive. For example, Address, address, and ADDRESS are different names.

• Start and end tags of an element must be identical.

• An element, which is a container, can contain text or elements as seen in the above example.

You might also like