SlideShare une entreprise Scribd logo
1  sur  28
1
XML Part2
Mrs.C.Santhiya
Assistant Professor
TCE,Madurai
2
Linking DTD and XML Docs
• Document Type Declaration in the XML document:
<!DOCTYPE article SYSTEM “http://www-dbs/article.dtd“>
keywords Root element URI for the DTD
3
Linking DTD and XML Docs
• Internal DTD:
<?xml version=“1.0“?>
<!DOCTYPE article [
<!ELEMENT article (title,author+,text)>
...
<!ELEMENT index (#PCDATA)>
]>
<article>
...
</article>
• Both ways can be mixed, internal DTD overwrites
external entity information:
<!DOCTYPE article SYSTEM „article.dtd“ [
<!ENTITY % pub_content (title+,author*,text)
]>
Internal & External DTD
• <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd">
• Note.dtd
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
4
• <?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>
5
Xml Display
• Displaying XML
Viewing XML Files
<?xml version="1.0" encoding="UTF-8"?>
- <note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
6
XMLHttpRequest Object
• var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the
document is ready:
document.getElementById("demo").innerHTML =
xhttp.responseText;
}
};
xhttp.open("GET", "filename", true);
xhttp.send();
7
• abort()
• getAllResponseHeaders()
• getResponseHeader()
• open(method,url,async,uname,pswd)
• send(string)
Properties
• Onreadystatechange
• readyState
• statusText
• Status
8
<html>
<body>
<h1>XMLHttpRequest</h1>
<p>The getAllResponseHeaders() function returns the header information of a resource, like length, server-type,
content-type, last-modified, etc:</p>
<p id="demo"></p>
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML =
this.getAllResponseHeaders();
}
};
xmlhttp.open("GET", "xmlhttp_info.txt", true);
xmlhttp.send();
</script>
</body>
</html>
9
Html DOM
<html>
<body>
<h1 id="demo">This is a Heading</h1>
<button type="button"
onclick="document.getElementById('demo').innerHTML = 'Hello World!'">Click
Me!
</button>
</body>
</html>
10
DOM Parser
• <script>
var text, parser, xmlDoc;
text = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";
parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");
document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
</script>
11
Xml with CSS
CATALOG.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/css" href=“CATALOG.css"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR> </CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR> </CD> </CATALOG>
12
CATALOG.css
CATALOG { background-color: #ffffff; width: 100%; }
CD { display: block; margin-bottom: 30pt; margin-left: 0; }
TITLE { display: block; color: #ff0000; font-size: 20pt; }
ARTIST { display: block; color: #0000ff; font-size: 20pt; }
COUNTRY, PRICE, YEAR, COMPANY { display: block; color: #000000; margin-left: 20pt; }
13
Xml with xpath
• <?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
• </bookstore>
14
Xpath
/bookstore/book[1]
/bookstore/book[last()]
/bookstore/book[last()-1]
/bookstore/book[position()<3]
//title[@lang]
//title[@lang='en‘]
/bookstore/book[price>35.00]
/bookstore/book[price>35.00]/title
15
Xsl elements
• <xsl :apply-templates>
• <xsl :apply-templates match=“expression”>
• <xsl :template>
• <xsl: for-each select=“expression”>
• <xsl :sort select=“expression”>
• <xsl:output>
16
Xml file
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with
plenty of real maple syrup</description>
<calories>650</calories>
</food>
</ breakfast_menu>
17
Xml with xslt
• <?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:output method=“html” />
<xsl:for-each select="breakfast_menu/food">
<div style="background-color:teal;color:white;padding:4px">
<span style="font-weight:bold"> <xsl:value-of select="name"/> - </span>
<xsl:value-of select="price"/>
</div>
<div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
<p>
    <xsl:value-of select="description"/>
<span style="font-style:italic"> (<xsl:value-of select="calories"/> calories per
serving)</span>
</p>
</div>
</xsl:for-each>
</body>
</html>
18
19
Xml Link
XLink Syntax
<?xml version="1.0" encoding="UTF-8"?>
<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
<homepage xlink:type="simple" xlink:href="http://www.w3sch
ools.com">Visit W3Schools</homepage>
<homepage xlink:type="simple" xlink:href="http://www.w3.org
">Visit W3C</homepage>
</homepages>
Specifications
•xlink:actuate
•xlink:href
•xlink:show
•xlink:type
20
Link
• <?xml version="1.0" encoding="UTF-8"?>
<bookstore xmlns:xlink="http://www.w3.org/1999/xlink">
<book title="Harry Potter">
<description
xlink:type="simple"
  xlink:href="/images/HPotter.gif"
  xlink:show="new">
As his fifth year at Hogwarts School of Witchcraft and
Wizardry approaches, 15-year-old Harry Potter is.......
</description>
</book>
• </bookstore>
21
XML - Namespaces
<?xml version="1.0" encoding="UTF-8"?>
<cont: contactxmlns:cont="www.tutorialspoint.com/profile">
<cont:name>Tanmay Patil</cont:name>
<cont:company>TutorialsPoint</cont:company>
<cont:phone>(011) 123-4567</cont:phone>
</cont:contact>
22
Xml with ids
• <?xml version="1.0" encoding="UTF-8"?>
<dogbreeds>
<dog breed="Rottweiler" id="Rottweiler">
<picture url="http://dog.com/rottweiler.gif" />
<history>The Rottweiler's ancestors were probably Roman
drover dogs.....</history>
<temperament>Confident, bold, alert and imposing, the Rottweiler
is a popular choice for its ability to protect....</temperament>
</dog>
• </dogbreeds>
23
Xml Schema
• Why Use an XML Schema?
• XML Schemas Support Data Types
• XML Schemas use XML Syntax
24
xsd
• Schema --- 1.Simple type(no child,attributes)
• restriction,built in data types.
• 2.Complex type(can contain)
• Simple content----no child,extension,restriction.
• Complex content------child,no limitations
25
XSD-Schema
• Syntax
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="x" type="y"/>
<xs:attribute name="x" type="y"/>
Example
Simple Type
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
26
Complex type
• <xml version=“1.0”>
• <schema xmlns=http://www.w3.org/2001/XMLSchema
• xmlns:computer= “”
• targetnamespace=“ “>
• <simpleType name=“gigahertz”>
• <restriction base=“decimal”>
• <mininclusive value=“2.1”/>
• </restriction>
• </simpleType>
• <complexType name=“CPU”>
• <simpleContent>
• <extension base=“string”>
• <attribute name=“model” type=“string”/>
• </extension>
• </simpleContent>
• </complexType>
27
Complex type
• <complexType name=“portable’>
• <all>
• <element name=“processor” type=“computer:cpu” />
• <element name=“monitor” type=“int” />
• <element name=“CPUSpeed” type=“computer:gigahertz” />
• <element name=“RAM” type=“int” />
• </all>
• <attribute name=“manufacturer” type=“string” />
• </complexType>
• </schema>
28

Contenu connexe

Tendances

Tendances (20)

Basics and different xml files used in android
Basics and different xml files used in androidBasics and different xml files used in android
Basics and different xml files used in android
 
Xml
XmlXml
Xml
 
HTML and XML Difference FAQs
HTML and XML Difference FAQsHTML and XML Difference FAQs
HTML and XML Difference FAQs
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
fundamentals of XML
fundamentals of XMLfundamentals of XML
fundamentals of XML
 
DTD
DTDDTD
DTD
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
Xml schema
Xml schemaXml schema
Xml schema
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
XML
XMLXML
XML
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Transforming xml with XSLT
Transforming  xml with XSLTTransforming  xml with XSLT
Transforming xml with XSLT
 
Regular expression unit2
Regular expression unit2Regular expression unit2
Regular expression unit2
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 
Xml schema
Xml schemaXml schema
Xml schema
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
 
XML
XMLXML
XML
 

Similaire à Xml p2 Lecture Notes

Xquery 131102171402-phpapp01
Xquery 131102171402-phpapp01Xquery 131102171402-phpapp01
Xquery 131102171402-phpapp01
Harish Bandi
 
Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)
Linux User's Group
 
art2830 1st html tag presentation
art2830 1st html tag presentationart2830 1st html tag presentation
art2830 1st html tag presentation
Oscar Au
 
Introduction to XML, XHTML and CSS
Introduction to XML, XHTML and CSSIntroduction to XML, XHTML and CSS
Introduction to XML, XHTML and CSS
Jussi Pohjolainen
 
vtu HTML+Course+Slide cse notes and .pdf
vtu HTML+Course+Slide cse notes and .pdfvtu HTML+Course+Slide cse notes and .pdf
vtu HTML+Course+Slide cse notes and .pdf
NaveenBhajantri1
 

Similaire à Xml p2 Lecture Notes (20)

XQuery
XQueryXQuery
XQuery
 
Xquery 131102171402-phpapp01
Xquery 131102171402-phpapp01Xquery 131102171402-phpapp01
Xquery 131102171402-phpapp01
 
Xml part 6
Xml part 6Xml part 6
Xml part 6
 
XML DTD and Schema
XML DTD and SchemaXML DTD and Schema
XML DTD and Schema
 
Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)Web Developement Workshop (Oct 2009 -Day 1)
Web Developement Workshop (Oct 2009 -Day 1)
 
Part 7
Part 7Part 7
Part 7
 
Html and css
Html and cssHtml and css
Html and css
 
Hyper Text Markup Language - Presentation.pptx
Hyper Text Markup Language - Presentation.pptxHyper Text Markup Language - Presentation.pptx
Hyper Text Markup Language - Presentation.pptx
 
BITM3730 9-13.pptx
BITM3730 9-13.pptxBITM3730 9-13.pptx
BITM3730 9-13.pptx
 
art2830 1st html tag presentation
art2830 1st html tag presentationart2830 1st html tag presentation
art2830 1st html tag presentation
 
Introduction to XML, XHTML and CSS
Introduction to XML, XHTML and CSSIntroduction to XML, XHTML and CSS
Introduction to XML, XHTML and CSS
 
Introduction to LINQ To XML
Introduction to LINQ To XMLIntroduction to LINQ To XML
Introduction to LINQ To XML
 
Html
HtmlHtml
Html
 
Html ppt
Html pptHtml ppt
Html ppt
 
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XMLFergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
 
INTRODUCTION TO HTML & CSS .pptx
INTRODUCTION TO HTML & CSS .pptxINTRODUCTION TO HTML & CSS .pptx
INTRODUCTION TO HTML & CSS .pptx
 
23xml
23xml23xml
23xml
 
XML's validation - DTD
XML's validation - DTDXML's validation - DTD
XML's validation - DTD
 
Unit 2 (it workshop)
Unit 2 (it workshop)Unit 2 (it workshop)
Unit 2 (it workshop)
 
vtu HTML+Course+Slide cse notes and .pdf
vtu HTML+Course+Slide cse notes and .pdfvtu HTML+Course+Slide cse notes and .pdf
vtu HTML+Course+Slide cse notes and .pdf
 

Plus de Santhiya Grace (8)

Xml p4 Lecture Notes
Xml p4  Lecture NotesXml p4  Lecture Notes
Xml p4 Lecture Notes
 
Xml p3 -Lecture Notes
Xml p3 -Lecture NotesXml p3 -Lecture Notes
Xml p3 -Lecture Notes
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Ajax Lecture Notes
Ajax Lecture NotesAjax Lecture Notes
Ajax Lecture Notes
 
Events Lecture Notes
Events Lecture NotesEvents Lecture Notes
Events Lecture Notes
 
Css lecture notes
Css lecture notesCss lecture notes
Css lecture notes
 
Software Quality Assurance
Software Quality AssuranceSoftware Quality Assurance
Software Quality Assurance
 
Software Quality Assurance class 1
Software Quality Assurance  class 1Software Quality Assurance  class 1
Software Quality Assurance class 1
 

Dernier

Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Dernier (20)

Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 

Xml p2 Lecture Notes

  • 2. 2 Linking DTD and XML Docs • Document Type Declaration in the XML document: <!DOCTYPE article SYSTEM “http://www-dbs/article.dtd“> keywords Root element URI for the DTD
  • 3. 3 Linking DTD and XML Docs • Internal DTD: <?xml version=“1.0“?> <!DOCTYPE article [ <!ELEMENT article (title,author+,text)> ... <!ELEMENT index (#PCDATA)> ]> <article> ... </article> • Both ways can be mixed, internal DTD overwrites external entity information: <!DOCTYPE article SYSTEM „article.dtd“ [ <!ENTITY % pub_content (title+,author*,text) ]>
  • 4. Internal & External DTD • <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE note SYSTEM "Note.dtd"> • Note.dtd <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> 4
  • 5. • <?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> 5
  • 6. Xml Display • Displaying XML Viewing XML Files <?xml version="1.0" encoding="UTF-8"?> - <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> 6
  • 7. XMLHttpRequest Object • var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { // Typical action to be performed when the document is ready: document.getElementById("demo").innerHTML = xhttp.responseText; } }; xhttp.open("GET", "filename", true); xhttp.send(); 7
  • 8. • abort() • getAllResponseHeaders() • getResponseHeader() • open(method,url,async,uname,pswd) • send(string) Properties • Onreadystatechange • readyState • statusText • Status 8
  • 9. <html> <body> <h1>XMLHttpRequest</h1> <p>The getAllResponseHeaders() function returns the header information of a resource, like length, server-type, content-type, last-modified, etc:</p> <p id="demo"></p> <script> var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange=function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.getAllResponseHeaders(); } }; xmlhttp.open("GET", "xmlhttp_info.txt", true); xmlhttp.send(); </script> </body> </html> 9
  • 10. Html DOM <html> <body> <h1 id="demo">This is a Heading</h1> <button type="button" onclick="document.getElementById('demo').innerHTML = 'Hello World!'">Click Me! </button> </body> </html> 10
  • 11. DOM Parser • <script> var text, parser, xmlDoc; text = "<bookstore><book>" + "<title>Everyday Italian</title>" + "<author>Giada De Laurentiis</author>" + "<year>2005</year>" + "</book></bookstore>"; parser = new DOMParser(); xmlDoc = parser.parseFromString(text,"text/xml"); document.getElementById("demo").innerHTML = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue; </script> 11
  • 12. Xml with CSS CATALOG.xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml-stylesheet type="text/css" href=“CATALOG.css"?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> </CATALOG> 12
  • 13. CATALOG.css CATALOG { background-color: #ffffff; width: 100%; } CD { display: block; margin-bottom: 30pt; margin-left: 0; } TITLE { display: block; color: #ff0000; font-size: 20pt; } ARTIST { display: block; color: #0000ff; font-size: 20pt; } COUNTRY, PRICE, YEAR, COMPANY { display: block; color: #000000; margin-left: 20pt; } 13
  • 14. Xml with xpath • <?xml version="1.0" encoding="UTF-8"?> <bookstore> <book category="cooking"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="children"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> • </bookstore> 14
  • 16. Xsl elements • <xsl :apply-templates> • <xsl :apply-templates match=“expression”> • <xsl :template> • <xsl: for-each select=“expression”> • <xsl :sort select=“expression”> • <xsl:output> 16
  • 17. Xml file <?xml version="1.0" encoding="UTF-8"?> <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description>Two of our famous Belgian Waffles with plenty of real maple syrup</description> <calories>650</calories> </food> </ breakfast_menu> 17
  • 18. Xml with xslt • <?xml version="1.0" encoding="UTF-8"?> <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE"> <xsl:output method=“html” /> <xsl:for-each select="breakfast_menu/food"> <div style="background-color:teal;color:white;padding:4px"> <span style="font-weight:bold"> <xsl:value-of select="name"/> - </span> <xsl:value-of select="price"/> </div> <div style="margin-left:20px;margin-bottom:1em;font-size:10pt"> <p>     <xsl:value-of select="description"/> <span style="font-style:italic"> (<xsl:value-of select="calories"/> calories per serving)</span> </p> </div> </xsl:for-each> </body> </html> 18
  • 19. 19
  • 20. Xml Link XLink Syntax <?xml version="1.0" encoding="UTF-8"?> <homepages xmlns:xlink="http://www.w3.org/1999/xlink"> <homepage xlink:type="simple" xlink:href="http://www.w3sch ools.com">Visit W3Schools</homepage> <homepage xlink:type="simple" xlink:href="http://www.w3.org ">Visit W3C</homepage> </homepages> Specifications •xlink:actuate •xlink:href •xlink:show •xlink:type 20
  • 21. Link • <?xml version="1.0" encoding="UTF-8"?> <bookstore xmlns:xlink="http://www.w3.org/1999/xlink"> <book title="Harry Potter"> <description xlink:type="simple"   xlink:href="/images/HPotter.gif"   xlink:show="new"> As his fifth year at Hogwarts School of Witchcraft and Wizardry approaches, 15-year-old Harry Potter is....... </description> </book> • </bookstore> 21
  • 22. XML - Namespaces <?xml version="1.0" encoding="UTF-8"?> <cont: contactxmlns:cont="www.tutorialspoint.com/profile"> <cont:name>Tanmay Patil</cont:name> <cont:company>TutorialsPoint</cont:company> <cont:phone>(011) 123-4567</cont:phone> </cont:contact> 22
  • 23. Xml with ids • <?xml version="1.0" encoding="UTF-8"?> <dogbreeds> <dog breed="Rottweiler" id="Rottweiler"> <picture url="http://dog.com/rottweiler.gif" /> <history>The Rottweiler's ancestors were probably Roman drover dogs.....</history> <temperament>Confident, bold, alert and imposing, the Rottweiler is a popular choice for its ability to protect....</temperament> </dog> • </dogbreeds> 23
  • 24. Xml Schema • Why Use an XML Schema? • XML Schemas Support Data Types • XML Schemas use XML Syntax 24
  • 25. xsd • Schema --- 1.Simple type(no child,attributes) • restriction,built in data types. • 2.Complex type(can contain) • Simple content----no child,extension,restriction. • Complex content------child,no limitations 25
  • 26. XSD-Schema • Syntax <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="x" type="y"/> <xs:attribute name="x" type="y"/> Example Simple Type <xs:element name="age"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> <xs:maxInclusive value="100"/> </xs:restriction> </xs:simpleType> </xs:element> 26
  • 27. Complex type • <xml version=“1.0”> • <schema xmlns=http://www.w3.org/2001/XMLSchema • xmlns:computer= “” • targetnamespace=“ “> • <simpleType name=“gigahertz”> • <restriction base=“decimal”> • <mininclusive value=“2.1”/> • </restriction> • </simpleType> • <complexType name=“CPU”> • <simpleContent> • <extension base=“string”> • <attribute name=“model” type=“string”/> • </extension> • </simpleContent> • </complexType> 27
  • 28. Complex type • <complexType name=“portable’> • <all> • <element name=“processor” type=“computer:cpu” /> • <element name=“monitor” type=“int” /> • <element name=“CPUSpeed” type=“computer:gigahertz” /> • <element name=“RAM” type=“int” /> • </all> • <attribute name=“manufacturer” type=“string” /> • </complexType> • </schema> 28