Internet Technology-LEC 8
Internet Technology-LEC 8
Summer 2020
By the end of this class, students will be able to:
Knowledge and Understanding Intellectual Skills
Learn XML XQuery, and AJAX
Run a simple code using XML XQuery, and AJAX
.
.
8
• When a user loads an XML document in a browser, a parser parses the
document, and the browser uses a style sheet to format the data for
display
• Google Chrome places a down arrow and right arrow next to every
container element; they’re not part of the XML document.
• down arrow indicates that the browser is displaying the container element’s child
elements
• clicking the right arrow next to an element expands that element
14
<?xml version="1.0" encoding="UTF-8"?>
15
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.
16
< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark
17
©1992-2012 by Pearson Education, Inc. All Rights Reserved. 18
An XML element is everything from (including) the
element's start tag to (including) the element's
end tag
<price>29.99</price>
A DTD defines the structure and the legal elements and attributes of an XML
document.
22
23
24
25
The keystone of AJAX is the XMLHttpRequest
object.
©1992-2012 by Pearson Education, Inc. All Rights Reserved. Revised by Dr. T. Tran for CSI3140 26
GET or POST?
GET is simpler and faster than POST, and can be used in most cases.
However, always use POST requests when:
27
28
29
AJAX can be used for
interactive communication
with an XML file.
30
31
function showCustomer(str) {
var xhttp;
if (str == "") { When a user selects
document.getElementById("txtHint").innerH getcustomer.php a customer in the
TML = "";
return; dropdown list above,
} a function called
xhttp = new XMLHttpRequest(); <?php
xhttp.onreadystatechange = function() { $mysqli
"showCustomer()" is
if (this.readyState == 4 && this.status = = new mysqli("servername", "username", "password" executed.
= 200) { , "dbname");
document.getElementById("txtHint").innerH if($mysqli->connect_error) {
TML = this.responseText; exit('Could not connect');
} }
};
xhttp.open("GET", "getcustomer.php?q="+str, $sql = "SELECT customerid, companyname,
true); contactname, address, city, postalcode, country
xhttp.send(); FROM customers WHERE customerid = ?";
}
32
33
XQuery is designed to query XML data.
XQuery is a language for finding and extracting elements and attributes from XML documents.
"Select all CD records with a price less than $10 from the CD collection stored in cd_catalog.xml"
©1992-2012 by Pearson Education, Inc. All Rights Reserved. Revised by Dr. T. Tran for CSI3140 34
XQuery can be used to:
• Extract information to use in a Web Service
• Generate summary reports
• Transform XML data to XHTML
• Search Web documents for relevant information
©1992-2012 by Pearson Education, Inc. All Rights Reserved. Revised by Dr. T. Tran for CSI3140 35
selects all book elements under the bookstore
for $x in doc("books.xml")/bookstore/book element into a variable called $x.
©1992-2012 by Pearson Education, Inc. All Rights Reserved. Revised by Dr. T. Tran for CSI3140 36
XQuery + HTML HTML
<ul> <ul>
{ <li><title lang="en">Everyday
for $x in Italian</title></li>
doc("books.xml")/bookstore/book/title <li><title lang="en">Harry Potter</title></li>
order by $x <li><title lang="en">Learning XML</title></li>
return <li>{$x}</li> <li><title lang="en">XQuery Kick
} Start</title></li>
</ul> </ul>
•Everyday Italian
•Harry Potter
•Learning XML
•XQuery Kick Start
37
Browser
Mohammed Abdelrazek
Email: