2. Introduction to XML
O XML is extensible markup language.
O XML case sensitive.
O XML was designed to store and transport
data.
O XML is often used for distributing data
over the Internet.
O XML documents form a tree structure.
Priyanka Pradhan
3. Introduction to XML
<?xml version=“1.0”?>
<student detail>
<name>rohit</name>
<branch>csit</branch>
</student detail>
ROOT
ELEMENT
CHILD
ELEMENT
Priyanka Pradhan
6. What is the DOM?
O The HTML DOM defines a standard way for
accessing and manipulating HTML documents. It
presents an HTML document as a tree-structure.
O The XML DOM defines a standard way for
accessing and manipulating XML documents. It
presents an XML document as a tree-structure.
Priyanka Pradhan
7. The XML DOM
O All XML elements can be accessed through the
XML DOM.
O A standard object model for XML
O A standard programming interface for XML
O Platform- and language-independent
O A W3C standard
O The XML DOM is a standard for how to get,
change, add, or delete XML elements.
Priyanka Pradhan
8. DTD
O It is Document type definition
O An XML document with correct syntax is
called well formed.
O An XML document validated against a DTD is
both well formed and valid.
Priyanka Pradhan
9. Node Parents, Children, and Siblings
O Parent nodes have children. Children on the same
level are called siblings (brothers or sisters).
O In a node tree, the top node is called the root
O Every node, except the root, has exactly one parent
node
O A node can have any number of children
O A leaf is a node with no children
O Siblings are nodes with the same parent
Priyanka Pradhan
10. PCDATA
O PCDATA - Parsed Character Data
O XML parsers normally parse all the text in an XML document.
O When an XML element is parsed, the text between the XML tags is also parsed:
<message>This text is also parsed</message>
O The parser does this because XML elements can contain other elements, as in this
example, where the <name> element contains two other elements (first and last):
<name><first>Bill</first><last>Gates</last></name>
O and the parser will break it up into sub-elements like this:
<name>
<first>Bill</first>
<last>Gates</last>
</name>
Priyanka Pradhan
11. CDATA - (Unparsed) Character Data
O The term CDATA is used about text data that should not be parsed
by the XML parser.
O Characters like "<" and "&" are illegal in XML elements.
O "<" will generate an error because the parser interprets it as the
start of a new element.
O "&" will generate an error because the parser interprets it as the
start of an character entity.
O Some text, like JavaScript code, contains a lot of "<" or "&"
characters. To avoid errors script code can be defined as CDATA.
O A CDATA section starts with "<![CDATA[" and ends with "]]>":
Priyanka Pradhan
12. What is XPath?
O XPath stands for XML Path Language
O XPath uses "path like" syntax to identify and
navigate nodes in an XML document
O XPath contains over 200 built-in functions
O XPath is a major element in the XSLT
standard
O XPath is a W3C recommendation
Priyanka Pradhan
13. XPath uses path expressions to select nodes or node-sets in an XML document.
Priyanka Pradhan
14. XSLT
OXSL (eXtensible Stylesheet Language)
is a styling language for XML.
OXSLT stands for XSL Transformations.
OXSLT is used to transform XML
documents into other formats (like
transforming XML into HTML).
Priyanka Pradhan
16. XSL(T) Languages
O XSLT is a language for transforming XML
documents.
O XPath is a language for navigating in XML
documents.
O XQuery is a language for querying XML
documents.
Priyanka Pradhan
17. What is a DTD?
O A DTD is a Document Type Definition.
O A DTD defines the structure and the legal
elements and attributes of an XML document.
O An application can use a DTD to verify that
XML data is valid.
Priyanka Pradhan
18. O If the DTD is declared inside the XML file, it
must be wrapped inside the <!DOCTYPE>
definition.
Priyanka Pradhan
19. O <?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
Priyanka Pradhan
20. The DTD is interpreted like this:
O !DOCTYPE note defines that the root element of this document is
note
O !ELEMENT note defines that the note element must contain four
elements: "to,from,heading,body"
O !ELEMENT to defines the to element to be of type "#PCDATA"
O !ELEMENT from defines the from element to be of type
"#PCDATA"
O !ELEMENT heading defines the heading element to be of type
"#PCDATA"
O !ELEMENT body defines the body element to be of type
"#PCDATA"
Priyanka Pradhan
21. An External DTD Declaration
O XML document with a reference to an external DTD
O <?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Priyanka Pradhan
22. O And here is the file "note.dtd", which contains
the DTD:
O <!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
Priyanka Pradhan
23. DTD - XML Building Blocks
O Elements
O Attributes
O Entities
O PCDATA
O CDATA
Priyanka Pradhan
24. Elements
O Elements are the main building blocks of
both XML and HTML documents.
O <body>some text</body>
<message>some text</message>
Priyanka Pradhan
27. DTD - Elements
<!ELEMENT element-name category>
or
<!ELEMENT element-name (element-content)>
Priyanka Pradhan
28. Empty Elements:
O <!ELEMENT element-name EMPTY>
Example:
<!ELEMENT br EMPTY>
XML example:
<br />
Priyanka Pradhan
29. Elements with Parsed Character
Data
O <!ELEMENT element-name (#PCDATA)>
Example:
<!ELEMENT from (#PCDATA)>
Priyanka Pradhan
30. Elements with any Contents
O <!ELEMENT element-name ANY>
Example:
<!ELEMENT note ANY>
Priyanka Pradhan
31. Elements with Children
(sequences)
O <!ELEMENT element-name (child1)>
or
<!ELEMENT element-name (child1,child2,...)>
Example:
<!ELEMENT note (to,from,heading,body)>
Priyanka Pradhan
32. Declaring Only One Occurrence
of an Element
O <!ELEMENT element-name (child-name)>
Example:
<!ELEMENT note (message)>
Priyanka Pradhan
33. Declaring Minimum One
Occurrence of an Element
O <!ELEMENT element-name (child-name+)>
Example:
<!ELEMENT note (message+)>
Priyanka Pradhan
34. Declaring Zero or More
Occurrences of an Element
O <!ELEMENT element-name (child-name*)>
Example:
<!ELEMENT note (message*)>
Priyanka Pradhan
35. Declaring Zero or One
Occurrences of an Element
O <!ELEMENT element-name (child-name?)>
Example:
<!ELEMENT note (message?)>
Priyanka Pradhan
47. What is an XML Schema?
O An XML Schema describes the structure of an
XML document.
O The XML Schema language is also referred to
as XML Schema Definition (XSD).
Priyanka Pradhan
49. O The purpose of an XML Schema is to define
the legal building blocks of an XML
document:
O the elements and attributes that can appear in a
document
O the number of (and order of) child elements
O data types for elements and attributes
O default and fixed values for elements and
attributes
Priyanka Pradhan
50. well-formed XML document
O it must begin with the XML declaration
O it must have one unique root element
O start-tags must have matching end-tags
O elements are case sensitive
O all elements must be closed
O all elements must be properly nested
O all attribute values must be quoted
O entities must be used for special characters
Priyanka Pradhan
51. A Simple XML Document
O <?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Priyanka Pradhan
52. A DTD File
O <!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
Priyanka Pradhan
54. A Reference to a DTD
O <?xml version="1.0"?>
<!DOCTYPE note SYSTEM
"https://www.w3schools.com/xml/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Priyanka Pradhan
55. A Reference to an XML Schema
O <?xml version="1.0"?>
<note
xmlns="https://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.w3schools.com/xml/note.xsd"
>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Priyanka Pradhan