Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 62

XML

Extensible Markup Language

XML
XML is a meta-language, which means
you create and format your own
document markups (tags).

XML Files
Three files are typically processed by
an XML compliant application.
1) The .xml document contains the
document data; XML elements,
attributes, and data content.

XML Files
2) The style sheet determines how the
documents should be formatted and
presented.

XML Files
3) The Document Type Definition
(DTD), or Schema, specifies rules for
how XML elements, attributes, and
data are defined structurally and how
they are logically related in an XML
compliant document.

XML Elements
XML elements consist of a start tag,
content, and an end tag. As with
XHTML:

XML Elements
1) An XML element name must start
with a letter or an underscore.
Numbers, hyphens, periods, or
additional underscores can follow, and
there is no limit to characters per
element.

XML Elements
2) Colons are permitted only for
specifying namespaces.
3) Whitespace and symbols are illegal
in an element name.

XML Elements
Non-empty elements must have a start
and end tag. Elements such as <p>
contain text and should be coded as
<p>.....</p>
<sales>..</sales>

XML Elements
XML supports empty elements,
typically used to add non-text content
to a document. XML empty elements
must still contain a forward slash.
<logosrc="company.gif"/>

10

XML Elements
XML tags must be nested correctly:
<partNumber>..<partName>..
</partName>..</partNumber>

11

XML Well-formedness
If these basic syntax rules are met in
your XML document, the document is
said to be well-formed.

12

XML Declaration
XML documents begin with the XML
declaration which specifies the XML
version used. The XML declaration,
while not mandatory for XHTML, is
mandatory in an XML document. The
initial portion of a document, preceding
the first element, is the prolog.
13

XML Prolog
The prolog contains only declarations,
whitespace, comments and processing
instructions.
<?xmlversion="1.0"?>
<?xmlstylesheet
type="text/css"
href="journey.css"?>
14

XML Syntax
XML is case sensitive. All declarations
and markup must match in case. This
applies throughout XML processing.
Additionally, the name XML is reserved.
You may not create an element,
attribute, or name a file beginning with
xml or XML.
15

XML Syntax
As with XHTML, attributes describe
additional information about an
element. Attributes consist of a name
and a value and must appear in the
start tag or the empty-element tag.

16

XML Attributes
The attribute name, paired with its
quoted value, is an attribute
specification.
<anthologyproverb="journey">

17

XML Attributes
The attribute value may use "" or
, but must always be quoted and
follow the same character restrictions
as element names.
There will be times with pairing an
element with an attribute specification
is less effective than creating
subelements (nested elements).
18

XML Comments
Comments in XML match comments in
XHTML. Comments should not nest
inside of a markup and cannot come
before the XML declaration:
<?xmlversion="1.0"?>
<!Comment.>
19

XML Comments
An illegal comment example:
<?xmlversion="1.0"?>
<name>NorthAir<!flight
schedulegoeshere></name>

20

XML Character Data


All XML documents consist of
characters. There are two types of
character data in XML documents:
PCDATA -which has to be parsed
CDATA -which is not parsed

21

XML Character Data


Elements consist of PCDATA and
attributes of CDATA.
A sample of PCDATA predeclared
names is:

22

XML Character Data


Character
<
>
"

&

Name
lt
gt
quot
apos
amp

Number
60
62
34
39
38
23

XML Character Data


To use the predeclared a name or
number, begin with the & delimiter for
characters or &# for numbers, and end
with the ; delimiter for either
characters or numbers.

24

XML Character Data


> is presented as &gt;
or as;
&#62;

25

XML Character Data


<condition>a>b&
c<b</condition>
is keyed:
<condition>a&gt;b&amp;c
&lt;b</condition>

26

XML Character Data


A CDATA section will have the following
form:
<![CDATA["<....>"]]>

27

XML Processing Instruction


Using processing instructions, it is
possible to incorporate applications not
performed by XML processor.
Processing instructions take the
following form:
<?NameTargetApplication
ApplicationInstructions?>
28

XML Processing Instruction


When a processing instruction is
included, it is often used to add a style
sheet, as in:
<?xmlstylesheet
type=text/css
href="example.css"?>

29

XML Entities
Entities have two parts, the declaration
(in the DTD) and the entity reference
(in the XML document).
There are two type of entities, general
and parameter. General entities are
included in XML documents and
parameter entities are included in
DTDs.
30

XML Entities
Entities must be declared in both the
XML document (general), and in the
DTD (parameter).

31

XML Entities
General entities can be declared as:
<!ENTITYnameOfEntity"This
isanexampleofinternal
entity">
for internal entities, and;

32

XML Entities
<!ENTITYnameOfEntitySYSTEM
"http.www.learningcentre.
org/entExam.txt">
for external entities saved outside of
the XML document, in the text element.

33

XML Entities
Parameter entities have a similar
declaration, with the exception of an
extra % character. The declaration of a
parameter entity will be:
<!ENTITY%nameOfEntity"This
isanexampleofparameter
entitydeclaration">
34

XML Entities
To insert your text into an XML
document, refer to it by the name of the
entity, inside of &...; delimiters. A
general internal entity of:
<!ENTITYadInfo"Replace
withsales/addressinfo">

35

XML Entities
Will to refer to:
&adInfo;
There is no space between &name
and ;

36

XML Entities
Parameter entities are referenced as:
%parEntName
Parameter entities only occur inside of
a DTD Document.

37

XML Prolog
When declaring an XML document, the
XML prolog is mandatory:
<?xmlversion="1.0"?>

38

XML Encoding Attribute


Optional encoding attribute represents
legal character encoding. There are
several encoding values, parsers must
support at least UTF-6 and UTF-16
Unicode. With an encoding attribute,
the XML prolog takes the form:
<?xmlversion="1.0"
encoding="UTF8"standalone
="yes">

39

XML Standalone Attribute


The standalone attribute can have
values of yes or no. The value yes
states required entity declarations are
within the XML document and the value
no states that the XML document will
have an external DTD.

40

XML Encoding Attribute


Changing encoding value incorporates
different character sets, enabling
writing XML documents in different
languages.
<?xmlversion="1.0"
encoding="ISO88592"?>

41

XML Namespace
The use of namespaces is not
mandatory in XML, but helps to ensure
uniqueness among XML elements.
The namespace is often declared in
the root element of the document but
may be in any element. The
namespace cannot be used until after it
has been declared.
42

XML Document Tree


The term document tree is used as a
metaphor for understanding the
relationships and order of the
document.

43

XML Document Tree


A document tree has only one root.
A document tree may have an
unbounded number of nodes, at any
level of the tree.

44

XML Document Tree


The document tree, made of one root
and multiple nodes, is referred to in the
parent-child hierarchy for the purpose
of planning, organizing, and accessing
data.

45

XML Document Tree


The relationships between the parents,
children, and siblings allow for ease of
navigation between nodes, ease of
adding additional nodes, and ease of
manipulating data within nodes.

46

XML Parsers
Parsers are tools that analyze XML
documents for correct syntax. There
are two types of parsers:
1) Non-validating parsers that ensure a
data object is well-formed
2) Validating parsers that use a DTD to
ensure the validity of a well-formed
data objects form and content

47

XML Parsers
Parsers start from the top of an XML
document, looking at the first elements
(typically within the prolog), checking to
see if the element meets XML syntax
rules. If the syntax is not correct,
possibly due to a tag not properly
closed, a message error appears and
parsing stops.
48

XML Parsers
After the error is corrected, the parser
will run again until it locates another
error. If there are no errors, an array is
built with data about the type of node,
and the parser proceeds to the next
element, again to check if it is wellformed.
49

XML Parsers
When the parser reaches a non-empty
element, it checks all of the elements
child nodes as it does for all other
nodes, again saving the information
about the node into the array.

50

XML Parsers
When the parser comes to the end of
the document and determines the
document is well-formed, it produces a
parse tree (a set of arrays) that can be
passed on to the XML processor.

51

XML Parsers
The arrays can be handed off to an
application using object properties via
an Application Programming Interface
(DOM as an example) or as a class an
application can refer to.

52

XML Parsers
A validating parser additionally
compares each element in the parse
tree to its associated DTD. The parser
may:

53

XML Parsers
1) Build a logic structure from the DTD
and match the document against this
structure
2) Iterate through the XML document
again and match the elements against
the DTD

54

XML Parsers
In addition to a tree-based parser, an
event-driven parser executes a callback to the application for each class
of XML data (elements with or without
attributes, processing instructions,
comments, notation).

55

XML Parsers
An event-driven parser doesnt
maintain the element tree structure or
any data after it parses. The eventdriven method, however, requires
modest system resources.

56

XML Parsers
The ability of a parser to check for
syntax errors potentially saves time in
application development. XML will not
run if the code isnt exactly correct.
Parsers can greatly increase the
functionality of the code. But what
about the functionality of the
application?
57

XML Modeling
You determine how well an XML
application functions for the user. Your
constant question should be:
What will we/they do with the data?

58

XML Modeling
The parser helps you to keep the
syntax for the document to run, but you
develop the application for the
document to be used. Parsing errors
can be corrected easily enough. Errors
in the planning phase can be difficult
and expensive to correct.
59

XML Modeling
Even in the simplest applications, it is
important to determine what data you
will need, how you will access the data,
what names will make the most
effective elements, and how will the
data be used.

60

XML Modeling
A constant focus on, "What is the
purpose? Who is the audience?" will
help you to design from the users
perspective.

61

XML
Extensible Markup Language
Last Slide

62

You might also like