SlideShare a Scribd company logo
1 of 33
Introduction to XML 
• XML is a extensible markup language like 
HTML. 
• The only difference between XML and HTML is 
that XML is used for documents containing 
structured information. 
• Structured information contains both content and 
some indication of what role that content 
performs. 
• XML is basically designed to describe data, it 
contains no pre-defined tag, and you must 
define your own tag in it. 
• It uses DTD and XML schema to describe the 
data.
Syntax 
• Extensible Markup Language (XML) is a set of rules 
for encoding documents in machine-readable form. 
• All XML Elements Must Have a Closing Tag: 
– In 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> 
• 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>
• 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> 
• XML Documents Must Have a Root Element: 
– XML 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> 
• 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. 
– Study the two XML documents below. The first one is incorrect, the second is 
correct: 
– <note date=12/11/2007> 
<to>Tove</to> 
<from>Jani</from> 
</note> 
– <note date="12/11/2007"> 
<to>Tove</to> 
<from>Jani</from> 
</note>
• Entity References: 
– Some characters have a special meaning in XML. 
– If you place a character like "<" inside an XML 
element, it will generate an error because the parser 
interprets it as the start of a new element. 
– This will generate an XML error: 
<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 
&quot “” quotation mark
• Comments in XML 
– The syntax for writing comments in XML is similar to that of 
HTML. 
– <!-- This is a comment --> 
• White-space is Preserved in XML 
– HTML truncates multiple white-space characters to one single 
white-space 
– HTML: Hello Tove 
– Output: Hello Tove 
– With XML, the white-space in a document is not truncated 
• XML Stores New Line as LF: 
– In Windows applications, a new line is normally stored as a pair 
of characters: carriage return (CR) and line feed (LF). In Unix 
applications, a new line is normally stored as an LF character. 
Macintosh applications also use an LF to store a new line. 
– XML stores a new line as LF.
DTDs and XML Schema 
• The purpose of a DTD is to define the 
legal building blocks of an XML document. 
• It defines the document structure with a 
list of legal elements. 
• A DTD can be declared inline in your XML 
document, or as an external reference. 
• Internal DTD 
– This is an XML document with a Document 
Type Definition
<?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>Meeting Tomorrow at 5 p.m</body> 
</note> 
In XML DTD, #PCDATA is the keyword to specify 
mixed content, meaning an element may contain 
character data.
• The DTD is interpreted like this: 
!ELEMENT note (in line 2) defines the 
element "note" as having four elements: 
"to,from,heading,body". 
!ELEMENT to (in line 3) defines the "to" 
element to be of the type "CDATA". 
!ELEMENT from (in line 4) defines the 
"from" element to be of the type "CDATA"
• External DTD 
– This is the same XML document with an external DTD 
<?xml version="1.0"?> 
<!DOCTYPE note SYSTEM "note.dtd"> 
<note> 
<to>Tove</to> <from>Jani</from> <heading>Reminder</heading> 
<body>Meeting Tomorrow at 5 p.m!</body> 
</note> 
– This is a copy of the file "note.dtd" containing the Document 
Type Definition: 
<?xml version="1.0"?> 
<!ELEMENT note (to,from,heading,body)> 
<!ELEMENT to (#PCDATA)> 
<!ELEMENT from (#PCDATA)> 
<!ELEMENT heading (#PCDATA)> 
<!ELEMENT body (#PCDATA)>
• Why use a DTD? 
– XML provides an application independent way of 
sharing data. 
– With a DTD, independent groups of people can agree 
to use a common DTD for interchanging data. 
– Your application can use a standard DTD to verify 
that data that you receive from the outside world is 
valid. 
– You can also use a DTD to verify your own data
XML Schema 
• An XML Schema describes the structure of an XML 
document. 
• XML Schema is an XML-based alternative to DTD. 
• The XML Schema language is also referred to as XML 
Schema Definition (XSD). 
• The purpose of an XML Schema is to define the legal 
building blocks of an XML document, just like a DTD. 
– defines elements that can appear in a document 
– defines attributes that can appear in a document 
– defines which elements are child elements 
– defines the order of child elements 
– defines the number of child elements 
– defines whether an element is empty or can include text 
– defines data types for elements and attributes 
– defines default and fixed values for elements and attributes
XML Schemas are the Successors of DTDs 
• We think that very soon XML Schemas will 
be used in most Web applications as a 
replacement for DTDs. Here are some 
reasons: 
– XML Schemas are extensible to future 
additions 
– XML Schemas are richer and more powerful 
than DTDs 
– XML Schemas are written in XML 
– XML Schemas support data types 
– XML Schemas support namespaces
• <?xml version="1.0"?> 
<xs:schema > 
<xs:element name="note"> 
<xs:complexType> 
<xs:sequence> 
<xs:element name="to" type="xs:string"/> 
<xs:element name="from" type="xs:string"/> 
<xs:element name="heading" type="xs:string"/> 
<xs:element name="body" type="xs:string"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
</xs:schema> 
• xsi:noNamespaceSchemaLocation=“Note.xs“ 
– insert into the root element of the XML document
• When defining XML Schema, the content you wish to put 
into an XML document must first be summarized. The 
next step is to create a tree structure. 
– Content to put into the XML document: 
• The root element is "Employee_Info" 
• As the content for "Employee_Info," "Employee" occurs 0 or more 
times 
• As content of "Employee," "Name," "Department," "Telephone," and 
"Email" elements occur once in respective order 
• "Name," "Department," "Telephone," and "Email" content are text 
strings 
• "Employee" has an attribute called "Employee_Number" 
• "Employee_Number" content must be int type
XPath 
• XPath is used to navigate through 
elements and attributes in an XML 
document. 
• XPath, the XML Path Language, is a 
query language for selecting nodes 
from an XML document 
• XPath includes over 100 built-in functions. 
There are functions for string values, 
numeric values, date and time 
comparison, Boolean values, and more.
<?xml version="1.0" encoding="ISO-8859-1"?> 
<catalog> 
<cd country="USA"> 
<title>Empire Burlesque</title> 
<artist>Bob Dylan</artist> 
<price>10.90</price> 
</cd> 
<cd country="UK"> 
<title>Hide your heart</title> 
<artist>Bonnie Tyler</artist> 
<price>10.0</price> 
</cd> 
<cd country="USA"> 
<title>Greatest Hits</title> 
<artist>Dolly Parton</artist> 
<price>9.90</price> 
</cd> 
</catalog>
using System.Xml; 
using System.Xml.XPath; 
.... 
string fileName = "data.xml"; 
XPathDocument doc = new XPathDocument(fileName); 
XPathNavigator nav = doc.CreateNavigator(); 
// Compile a standard XPath expression 
XPathExpression expr; 
expr = nav.Compile("/catalog/cd[price>=10.0]/price"); 
XPathNodeIterator iterator = nav.Select(expr); 
// Iterate on the node set 
listBox1.Items.Clear(); 
try 
{ 
while (iterator.MoveNext()) 
{ 
XPathNavigator nav2 = iterator.Current.Clone(); 
listBox1.Items.Add("price: " + nav2.Value); 
} 
} 
catch(Exception ex) 
{ 
Console.WriteLine(ex.Message); 
}
/catalog/cd[1] selects the first cd child of 
catalog 
/catalog/cd[last()] selects the last cd child of 
catalog 
/catalog/cd[price] selects all the cd elements that 
have price 
/ 
catalog/cd[price= 
10.90] 
selects cd elements with the 
price of 10.90 
/ 
catalog/cd[price= 
10.90]/price 
selects all price elements with 
the price of 10.90
• What is XSLT 
– Extensible Stylesheet Language 
Transformation 
– Name is misleading 
– Stylesheet 
• implies it makes things look like something 
• not necessarily or usually true 
Name should have been 
• “The XML Transformation Language”
• What XSLT Does is “Transform” 
– Transform means change 
Reads XML documents and writes 
– HTML for browsers 
– interchange file (RTF, RDF, EDI, etc.) 
– a flat ASCII file (plain text, comma separated 
etc.)
• Transform It into HTML (convert to 
HTML and display in a browser)
• Transform It into PDF (convert to PDF 
and display with Acrobat) 
• Transform It into QuarkXPress 
• Transform It into a Database Load File 
– Key: 00095AUS 
– EMPNO: 009 
– 001:USDIN 
– 002:Sasparilla 
– 008:36 
– 014:70 
– 020:Deputy in Charge of Chewables
Logical Components of an XSLT 
Application 
• (needs XSLT processing software 
called an “XSLT Engine”) 
• Reads XML document(s) (tags and text) 
• Uses an XSLT stylesheet/transform (the 
program) 
• Runs using XSLT processing software 
(called an XSLT Engine) 
• Produces output document(s)
Structure of an XSLT System
XMLXSLT.xml 
<?xml version="1.0" encoding="utf-8" ?> 
<?xml-stylesheet type="text/xsl" href="XSLTFile.xsl" ?> 
<employee> 
<demo>Look</demo> 
<demo>Formatting</demo> 
<demo>XML</demo> 
<demo>as a HTML</demo> 
</employee>
XSLTFile.xsl 
<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match ="/"> 
<html> 
<head> 
<titel>XSLT Test</titel> 
</head> 
<body> 
<xsl:for-each select ="employee/demo"> 
<h1> 
<xsl:value-of select ="."/> 
</h1> 
</xsl:for-each> 
</body> 
</html> 
</xsl:template> 
</xsl:stylesheet>
• The next element, <xsl:stylesheet>, defines 
that this document is an XSLT style sheet 
document (along with the version number and 
XSLT namespace attributes). 
• The <xsl:template> element defines a template. 
The match="/" attribute associates the template 
with the root of the XML source document. 
• The content inside the <xsl:template> element 
defines some HTML to write to the output. 
• The last two lines define the end of the template 
and the end of the style sheet. 
• The <xsl:value-of> element can be used to 
extract the value of an XML element and add it 
to the output stream of the transformation:
• We can also filter the output from the XML 
file by adding a criterion to the select 
attribute in the <xsl:for-each> element. 
<xsl:for-each 
select="catalog/cd[artist='Bob Dylan']">
Table format of xslt file 
<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 
<html> 
<body> 
<h2>My CD Collection</h2> 
<table border="1"> 
<tr bgcolor="#9acd32"> 
<th>Title</th> 
<th>Artist</th> 
</tr> 
<tr> 
<td><xsl:value-of select="catalog/cd/title"/></td> 
<td><xsl:value-of select="catalog/cd/artist"/></td> 
</tr> 
</table> 
</body> 
</html> 
</xsl:template> 
</xsl:stylesheet>
Sax and DOM 
• SAX (Simple API for XML) is an event-based 
sequential access parser API. 
• It provides a mechanism of reading data 
from xml. 
• parsing means syntactic analysis, is the process 
of analyzing a text, made of a sequence of 
tokens (for example, words), to determine its 
grammatical structure with respect to a given 
(more or less) formal grammar. 
• SAX provides a mechanism for reading data 
from an XML document that is an alternative to 
that provided by the Document Object Model 
(DOM).
Benefits of Sax over DOM 
• SAX parsers have certain benefits over DOM-style 
parsers. 
• The quantity of memory that a SAX parser must use in 
order to function is typically much smaller than that of a 
DOM parser. 
• DOM parsers must have the entire tree in memory 
before any processing can begin, so the amount of 
memory used by a DOM parser depends entirely on the 
size of the input data. 
• Because of the event-driven nature of SAX, processing 
documents can often be faster than DOM-style parsers. 
– Memory allocation takes time, so the larger memory footprint of 
the DOM is also a performance issue. 
• Processing XML documents larger than main memory is 
also impossible with DOM parsers, but can be done with 
SAX parsers.
DOM 
• The XML DOM defines a standard way for 
accessing and manipulating XML 
documents. 
• It also provides an application 
programming interface for working with 
XML data. 
• The DOM is designed to be used with any 
programming language. such as C/C++, 
Visual Basic, VBScript, and JScript.

More Related Content

What's hot (20)

Chapter4
Chapter4Chapter4
Chapter4
 
XML
XMLXML
XML
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
DOM and SAX
DOM and SAXDOM and SAX
DOM and SAX
 
Python xml processing
Python   xml processingPython   xml processing
Python xml processing
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
Xml
XmlXml
Xml
 
XMl
XMlXMl
XMl
 
Xml passing in python
Xml passing in pythonXml passing in python
Xml passing in python
 
Processing XML
Processing XMLProcessing XML
Processing XML
 
Querring xml with xpath
Querring xml with xpath Querring xml with xpath
Querring xml with xpath
 
XML and XSLT
XML and XSLTXML and XSLT
XML and XSLT
 
Xml databases
Xml databasesXml databases
Xml databases
 
Xml
XmlXml
Xml
 
Introduction to XML and Databases
Introduction to XML and DatabasesIntroduction to XML and Databases
Introduction to XML and Databases
 
Xml and xml processor
Xml and xml processorXml and xml processor
Xml and xml processor
 
XML
XMLXML
XML
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
XML XSLT
XML XSLTXML XSLT
XML XSLT
 

Similar to Xml and DTD's (20)

Unit 5 xml (1)
Unit 5   xml (1)Unit 5   xml (1)
Unit 5 xml (1)
 
1 xml fundamentals
1 xml fundamentals1 xml fundamentals
1 xml fundamentals
 
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5   XMLM.FLORENCE DAYANA WEB DESIGN -Unit 5   XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
Xml session
Xml sessionXml session
Xml session
 
Xml intro1
Xml intro1Xml intro1
Xml intro1
 
XML-Unit 1.ppt
XML-Unit 1.pptXML-Unit 1.ppt
XML-Unit 1.ppt
 
Web Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdfWeb Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdf
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 
XML notes.pptx
XML notes.pptxXML notes.pptx
XML notes.pptx
 
Ch2 neworder
Ch2 neworderCh2 neworder
Ch2 neworder
 
Xml 1
Xml 1Xml 1
Xml 1
 
Xsd
XsdXsd
Xsd
 
Xsd
XsdXsd
Xsd
 
Xml
XmlXml
Xml
 
Xml11
Xml11Xml11
Xml11
 
Xml Presentation-1
Xml Presentation-1Xml Presentation-1
Xml Presentation-1
 
Xml
XmlXml
Xml
 
Xml
XmlXml
Xml
 

Recently uploaded

Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 

Recently uploaded (20)

Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 

Xml and DTD's

  • 1. Introduction to XML • XML is a extensible markup language like HTML. • The only difference between XML and HTML is that XML is used for documents containing structured information. • Structured information contains both content and some indication of what role that content performs. • XML is basically designed to describe data, it contains no pre-defined tag, and you must define your own tag in it. • It uses DTD and XML schema to describe the data.
  • 2. Syntax • Extensible Markup Language (XML) is a set of rules for encoding documents in machine-readable form. • All XML Elements Must Have a Closing Tag: – In 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> • 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>
  • 3. • 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> • XML Documents Must Have a Root Element: – XML 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> • 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. – Study the two XML documents below. The first one is incorrect, the second is correct: – <note date=12/11/2007> <to>Tove</to> <from>Jani</from> </note> – <note date="12/11/2007"> <to>Tove</to> <from>Jani</from> </note>
  • 4. • Entity References: – Some characters have a special meaning in XML. – If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element. – This will generate an XML error: <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:
  • 5. &lt; < Less than &gt; > Greater than &amp; & ampersand &quot “” quotation mark
  • 6. • Comments in XML – The syntax for writing comments in XML is similar to that of HTML. – <!-- This is a comment --> • White-space is Preserved in XML – HTML truncates multiple white-space characters to one single white-space – HTML: Hello Tove – Output: Hello Tove – With XML, the white-space in a document is not truncated • XML Stores New Line as LF: – In Windows applications, a new line is normally stored as a pair of characters: carriage return (CR) and line feed (LF). In Unix applications, a new line is normally stored as an LF character. Macintosh applications also use an LF to store a new line. – XML stores a new line as LF.
  • 7. DTDs and XML Schema • The purpose of a DTD is to define the legal building blocks of an XML document. • It defines the document structure with a list of legal elements. • A DTD can be declared inline in your XML document, or as an external reference. • Internal DTD – This is an XML document with a Document Type Definition
  • 8. <?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>Meeting Tomorrow at 5 p.m</body> </note> In XML DTD, #PCDATA is the keyword to specify mixed content, meaning an element may contain character data.
  • 9. • The DTD is interpreted like this: !ELEMENT note (in line 2) defines the element "note" as having four elements: "to,from,heading,body". !ELEMENT to (in line 3) defines the "to" element to be of the type "CDATA". !ELEMENT from (in line 4) defines the "from" element to be of the type "CDATA"
  • 10. • External DTD – This is the same XML document with an external DTD <?xml version="1.0"?> <!DOCTYPE note SYSTEM "note.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Meeting Tomorrow at 5 p.m!</body> </note> – This is a copy of the file "note.dtd" containing the Document Type Definition: <?xml version="1.0"?> <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>
  • 11. • Why use a DTD? – XML provides an application independent way of sharing data. – With a DTD, independent groups of people can agree to use a common DTD for interchanging data. – Your application can use a standard DTD to verify that data that you receive from the outside world is valid. – You can also use a DTD to verify your own data
  • 12. XML Schema • An XML Schema describes the structure of an XML document. • XML Schema is an XML-based alternative to DTD. • The XML Schema language is also referred to as XML Schema Definition (XSD). • The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD. – defines elements that can appear in a document – defines attributes that can appear in a document – defines which elements are child elements – defines the order of child elements – defines the number of child elements – defines whether an element is empty or can include text – defines data types for elements and attributes – defines default and fixed values for elements and attributes
  • 13. XML Schemas are the Successors of DTDs • We think that very soon XML Schemas will be used in most Web applications as a replacement for DTDs. Here are some reasons: – XML Schemas are extensible to future additions – XML Schemas are richer and more powerful than DTDs – XML Schemas are written in XML – XML Schemas support data types – XML Schemas support namespaces
  • 14. • <?xml version="1.0"?> <xs:schema > <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> • xsi:noNamespaceSchemaLocation=“Note.xs“ – insert into the root element of the XML document
  • 15. • When defining XML Schema, the content you wish to put into an XML document must first be summarized. The next step is to create a tree structure. – Content to put into the XML document: • The root element is "Employee_Info" • As the content for "Employee_Info," "Employee" occurs 0 or more times • As content of "Employee," "Name," "Department," "Telephone," and "Email" elements occur once in respective order • "Name," "Department," "Telephone," and "Email" content are text strings • "Employee" has an attribute called "Employee_Number" • "Employee_Number" content must be int type
  • 16. XPath • XPath is used to navigate through elements and attributes in an XML document. • XPath, the XML Path Language, is a query language for selecting nodes from an XML document • XPath includes over 100 built-in functions. There are functions for string values, numeric values, date and time comparison, Boolean values, and more.
  • 17. <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd country="USA"> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <price>10.90</price> </cd> <cd country="UK"> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <price>10.0</price> </cd> <cd country="USA"> <title>Greatest Hits</title> <artist>Dolly Parton</artist> <price>9.90</price> </cd> </catalog>
  • 18. using System.Xml; using System.Xml.XPath; .... string fileName = "data.xml"; XPathDocument doc = new XPathDocument(fileName); XPathNavigator nav = doc.CreateNavigator(); // Compile a standard XPath expression XPathExpression expr; expr = nav.Compile("/catalog/cd[price>=10.0]/price"); XPathNodeIterator iterator = nav.Select(expr); // Iterate on the node set listBox1.Items.Clear(); try { while (iterator.MoveNext()) { XPathNavigator nav2 = iterator.Current.Clone(); listBox1.Items.Add("price: " + nav2.Value); } } catch(Exception ex) { Console.WriteLine(ex.Message); }
  • 19. /catalog/cd[1] selects the first cd child of catalog /catalog/cd[last()] selects the last cd child of catalog /catalog/cd[price] selects all the cd elements that have price / catalog/cd[price= 10.90] selects cd elements with the price of 10.90 / catalog/cd[price= 10.90]/price selects all price elements with the price of 10.90
  • 20. • What is XSLT – Extensible Stylesheet Language Transformation – Name is misleading – Stylesheet • implies it makes things look like something • not necessarily or usually true Name should have been • “The XML Transformation Language”
  • 21. • What XSLT Does is “Transform” – Transform means change Reads XML documents and writes – HTML for browsers – interchange file (RTF, RDF, EDI, etc.) – a flat ASCII file (plain text, comma separated etc.)
  • 22. • Transform It into HTML (convert to HTML and display in a browser)
  • 23. • Transform It into PDF (convert to PDF and display with Acrobat) • Transform It into QuarkXPress • Transform It into a Database Load File – Key: 00095AUS – EMPNO: 009 – 001:USDIN – 002:Sasparilla – 008:36 – 014:70 – 020:Deputy in Charge of Chewables
  • 24. Logical Components of an XSLT Application • (needs XSLT processing software called an “XSLT Engine”) • Reads XML document(s) (tags and text) • Uses an XSLT stylesheet/transform (the program) • Runs using XSLT processing software (called an XSLT Engine) • Produces output document(s)
  • 25. Structure of an XSLT System
  • 26. XMLXSLT.xml <?xml version="1.0" encoding="utf-8" ?> <?xml-stylesheet type="text/xsl" href="XSLTFile.xsl" ?> <employee> <demo>Look</demo> <demo>Formatting</demo> <demo>XML</demo> <demo>as a HTML</demo> </employee>
  • 27. XSLTFile.xsl <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match ="/"> <html> <head> <titel>XSLT Test</titel> </head> <body> <xsl:for-each select ="employee/demo"> <h1> <xsl:value-of select ="."/> </h1> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
  • 28. • The next element, <xsl:stylesheet>, defines that this document is an XSLT style sheet document (along with the version number and XSLT namespace attributes). • The <xsl:template> element defines a template. The match="/" attribute associates the template with the root of the XML source document. • The content inside the <xsl:template> element defines some HTML to write to the output. • The last two lines define the end of the template and the end of the style sheet. • The <xsl:value-of> element can be used to extract the value of an XML element and add it to the output stream of the transformation:
  • 29. • We can also filter the output from the XML file by adding a criterion to the select attribute in the <xsl:for-each> element. <xsl:for-each select="catalog/cd[artist='Bob Dylan']">
  • 30. Table format of xslt file <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <tr> <td><xsl:value-of select="catalog/cd/title"/></td> <td><xsl:value-of select="catalog/cd/artist"/></td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet>
  • 31. Sax and DOM • SAX (Simple API for XML) is an event-based sequential access parser API. • It provides a mechanism of reading data from xml. • parsing means syntactic analysis, is the process of analyzing a text, made of a sequence of tokens (for example, words), to determine its grammatical structure with respect to a given (more or less) formal grammar. • SAX provides a mechanism for reading data from an XML document that is an alternative to that provided by the Document Object Model (DOM).
  • 32. Benefits of Sax over DOM • SAX parsers have certain benefits over DOM-style parsers. • The quantity of memory that a SAX parser must use in order to function is typically much smaller than that of a DOM parser. • DOM parsers must have the entire tree in memory before any processing can begin, so the amount of memory used by a DOM parser depends entirely on the size of the input data. • Because of the event-driven nature of SAX, processing documents can often be faster than DOM-style parsers. – Memory allocation takes time, so the larger memory footprint of the DOM is also a performance issue. • Processing XML documents larger than main memory is also impossible with DOM parsers, but can be done with SAX parsers.
  • 33. DOM • The XML DOM defines a standard way for accessing and manipulating XML documents. • It also provides an application programming interface for working with XML data. • The DOM is designed to be used with any programming language. such as C/C++, Visual Basic, VBScript, and JScript.