Date post: | 10-Apr-2018 |
Category: |
Documents |
Upload: | jakaltarget |
View: | 241 times |
Download: | 5 times |
of 47
8/8/2019 Web Tech Class 7
1/47
1
Mr. Debojit Boro
Assistant Professor,Tezpur University,Napaam,Tezpur-784028
Web Technology
Batches:
M.Tech. 2nd Semester
B.Tech 6th Semester
B.Tech. 8th Semester
MCA 4th Semester
B.Tech. Electronics 8th Semester
1
8/8/2019 Web Tech Class 7
2/47
2
Topics for today
XSLT
XPATH
XQUERY
XMLSCHEMA
Browser Architecture
Mr. Debojit Boro
Assistant Professor,Tezpur University,Napaam,Tezpur-7840282
8/8/2019 Web Tech Class 7
3/47
3
Various components of XML
8/8/2019 Web Tech Class 7
4/47
4
XSLT (Extensible Style Sheets
Language Transformations)
XSLT is a language for transforming XML documentsinto XHTML documents or to other XML documents
XSLT uses XPath to find information in an XMLdocument
8/8/2019 Web Tech Class 7
5/47
5
XSLT uses XPath to define parts of the
source document that should match one ormore predefined templates. When a match isfound, XSLT will transform the matching partof the source document into the resultdocument.
For Learning the XSLT refer to the previous
.ppt (Web Tech Class 6.ppt)
8/8/2019 Web Tech Class 7
6/47
6
XPATH
This is used to navigate through the elements andattributes in XML document
XPath is a syntax for defining parts of an XML document
XPath uses path expressions to navigate in XML
documents
XPath contains a library of standard functions
XPath is a major element in XSLT
XPath is a W3C recommendation
Over 1000 built-in standard functions like date-timecomparision
This XPATH is used in XSLT documents
8/8/2019 Web Tech Class 7
7/47
7
XPATH uses seven kinds of nodes
1) element
2) attribute
3) text
4) namespace5) processing-instruction
6) comment
7) document nodes
8/8/2019 Web Tech Class 7
8/47
8
XPATH Syntax
XPATH uses path expressions to select nodes or node-sets ina XML document
Expression Description
nodename Select all child nodes of the named nodes/ Selects from the root node
// Selects nodes in the document from thecurrent node that match the selection nomatter where they are in the document
. Selects the current node
.. Selects the parent of the current node
@ Selects attributes
8/8/2019 Web Tech Class 7
9/47
9
1010
Juliana Dantas
IT
25000
Pedro Almeida
1011
>Leonardo Nasimeta
IT
30000
Pedro Almeida
Example ofXML file emp.xml referencing emp.xsl
Note*: We ll be refering to this example on all cases
8/8/2019 Web Tech Class 7
10/47
10
Path Expressions
Eg.1. Select all the child nodes of the PAYROLL element
Path Expression: PAYROLL
Eg.2. Select all EMPLOYEE elements that are children of PAYROLL
Path Expression: PAYROLL/EMPLOYEE
Eg.3
Select all attributes that are named status
Path Expression: //@status
8/8/2019 Web Tech Class 7
11/47
11
Predicates
Predicates are used in the path expressions to find a specific node or anode that contains a specific value. They are used within the brackets
[ predicates]
Eg.1. Select the first EMPLOYEE element that is the child of the PAYROLL
element.
Path Expression: /PAYROLL/EMPLOYEE[1]
Eg.2. Select the first two EMPLOYEE elements that are children of thePAYROLL element
Path Expression: /PAYROLL/EMPLOYEE[position()
8/8/2019 Web Tech Class 7
12/47
12
Some Predicates used are:
Last() Position()
Note*: Remember Predicates can beattributes or even elements itself. Its just away of defining a specific condition
8/8/2019 Web Tech Class 7
13/47
13
For selecting unknown nodes
Wildcard characters are also used in XPATH expressions such as
* - Matches any attribute nodes
eg. Select all the child nodes of the PAYROLL element/PAYROLL/*
@* - Matches any attribute nodes
eg. Select all NAME elements which have any attribute//NAME[@*]
Node() Matches any nodes
8/8/2019 Web Tech Class 7
14/47
14
Node sets in the XML document can also be returned
using several path using | character
E.g. Selects all the NAME elements of the EMPLOYEE element ofthe PAYROLL element AND all the BASICPAY elements in the
document
Path Expression: /PAYROLL/EMPLOYEE/NAME | //BASICPAY
8/8/2019 Web Tech Class 7
15/47
15
XPATH Axes
It is used to define a node set relative to the current node
Some of the axes are as:
AxisName Result
Ancestor Selects all ancestors (parent, grandparent, etc.) of the current node
ancestor-or-self Selects all ancestors (parent, grandparent, etc.) of the current node and the
current node itself
Attribute Selects all attributes of the current node
Child Selects all children of the current node
Descendant Selects all descendants (children, grandchildren, etc.) of the current node
descendant-or-self Selects all descendants (children, grandchildren, etc.) of the current node and the
current node itself
Following Selects everything in the document after the closing tag of the current node
following-sibling Selects all siblings after the current node
Namespace Selects all namespace nodes of the current nodeParent Selects the parent of the current node
Preceding Selects everything in the document that is before the start tag of the current node
preceding-sibling Selects all siblings before the current node
Self Selects the current node
8/8/2019 Web Tech Class 7
16/47
16
Location Path Expression
A location path can be absolute or relative.
An absolute location path starts with a slash ( / ) and arelative location path does not. In both cases the locationpath consists of one or more steps, each separated by aslash:
An absolute location path:
/step/step/...
A relative location path:
step/step/...
8/8/2019 Web Tech Class 7
17/47
17
Location Path Expression Syntax
The syntax for a location step is:
axisname::nodetest[predicate]
e.g Selects all EMPLOYEE nodes that are children of the current node
LPE: child::EMPLOYEE
e.g Selects all EMPLOYEE ancestors of the current node - and the
current as well if it is a EMPLOYEE node
LPE: ancestor-or-self::EMPLOYEE
8/8/2019 Web Tech Class 7
18/47
18
XPATH Operators
Returns either a node-set, a string, a Boolean, or a number.
Some Operators are:
|,+,-,div,=,,=,or, and, mod etc.
8/8/2019 Web Tech Class 7
19/47
19
XPATH implementation
/PAYROLL/EMPLOYEE/NAME
This XPATH expression needs to be embedded in HTML code asbelow
function loadXMLDoc(dname) { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",dname,false); xhttp.send(""); return xhttp.responseXML; }
8/8/2019 Web Tech Class 7
20/47
20
xml=loadXMLDoc(emp.xml"); path="/PAYROLL/EMPLOYEE/NAME"
// code for IE if (window.ActiveXObject) { var nodes=xml.selectNodes(path); for (i=0;i
8/8/2019 Web Tech Class 7
21/47
21
SelfStudy
Go through XPATH functions
8/8/2019 Web Tech Class 7
22/47
22
XQUERY
The logic is similar to the query languages that we use inSQL for the database.
XQUERY is used to query to XML data from the XML
documents
XQuery is built on XPath expressions
XQuery and XPath share the same data model andsupport the same functions and operators
8/8/2019 Web Tech Class 7
23/47
23
Use ofXQUERY
Extract information to use in a Web Service
Generate summary reports
Transform XML data to XHTML
Search Web documents for relevantinformation
8/8/2019 Web Tech Class 7
24/47
24
We ll be referring to the same example emp.xml
Doc() function used by XQUERY to extract data from theXML documents alongwith the path expressions.
doc(emp.xml) /PAYROLL/EMPLOYEE/NAME
The resultant of XQUERY ll be
Leonardo Nasimeto
8/8/2019 Web Tech Class 7
25/47
25
Use of Predicates in XQUERY
doc(emp.xml") /PAYROLL/EMPLOYEE[BASICPAY>25000]
Where [BASICPAY>25000]is the Predicate
Resultant ll be
1011
>Leonardo Nasimeta
IT
30000
Pedro Almeida
8/8/2019 Web Tech Class 7
26/47
26
XQUERY FLWOR Expressions
FLWOR stands for For,Let, Where,Order By, Return
Path Expression:
doc(emp.xml") /PAYROLL/EMPLOYEE[BASICPAY>25000]/NAME
The corresponding FLWOR expression ll be
for $x in doc(emp.xml")/PAYROLL/EMPLOYEE
where $x/BASICPAY>25000
return $x/NAME
XQUERY resultant ll be
8/8/2019 Web Tech Class 7
27/47
27
Embedding it in HTML
{for $x in doc(emp.xml")/PAYROLL/EMPLOYEE/NAMEorder by $xreturn {$x}}
The resultant ll be
Leonardo Nasimeto
8/8/2019 Web Tech Class 7
28/47
28
Or to show data
{for $x in doc(emp.xml")/PAYROLL/EMPLOYEE/NAMEorder by $xreturn {data($x)}}
The resultant ll be
Juliana DantasLeonardo Nasimeto
8/8/2019 Web Tech Class 7
29/47
29
XQUERY conditional expressions
Like If-then-Else expressions
for $x in doc(emp.xml")/PAYROLL/EMPLOYEE/NAMEreturn if ($x/@status=contractual")then {data($x/NAME)}else {data($x/NAME)}
Adding text
Employee Details
{for $x in doc(emp.xml")/PAYROLL/EMPLOYEEorder by $x/NAMEreturn {data($x/NAME)}. Category: {data($x/@status}}
8/8/2019 Web Tech Class 7
30/47
30
Some XQUERY functions
let $name := (substring($NAME,1,4))
Note: Explore for other XQUERY functions
User defined XQUERY functions
Syntax:
declare functionprefix:function_name($parameterAS datatype)AS returnDatatype{...function code here...}
8/8/2019 Web Tech Class 7
31/47
8/8/2019 Web Tech Class 7
32/47
32
XSCHEMA
It is a document that describes the structure
of the XML document related to elements thatcan appear in the document, about the orderof the elements etc.
8/8/2019 Web Tech Class 7
33/47
33
Definitions defined by XSCHEMA
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 includetext
defines data types for elements and attributes defines default and fixed values for elements and
attributes
8/8/2019 Web Tech Class 7
34/47
34
XSCHEMA Elements
Simple Element:The element that contains only text and do not contain anyother sub elements and attributes
syntax:
Complex Element:The element the contains other elements and attributes
8/8/2019 Web Tech Class 7
35/47
35
XSCHEMA Data Types
Some Data Types of XSCHEMA that arecommonly used:
xs:string xs:decimal
xs:integer
xs:boolean
xs:date
xs:time
8/8/2019 Web Tech Class 7
36/47
36
XSCHEMA Indicators
Indicators are used to control the usage of XML documents
Three categories and Seven Indicators
Order indicators: Defines the order of the elementsAllChoiceSequence
Occurrence indicators: Defines the number of usage of elementsmaxOccurs
minOccurs
Group indicators: Defines related sets of elementsGroup nameattributeGroup name
8/8/2019 Web Tech Class 7
37/47
8/8/2019 Web Tech Class 7
38/47
38
Sequence Indicator: Specifies that the child elements must appearin a specific order
maxOccurs Indicator:specifies the maximum number of times anelement can occur
8/8/2019 Web Tech Class 7
39/47
39
minOccurs Indicator:Specifies the minimum number of times anelement can occur
Groupname:Element groups are defined with the group declaration
8/8/2019 Web Tech Class 7
40/47
40
Attribute GroupName: Attribute groups are defined within this
8/8/2019 Web Tech Class 7
41/47
41
John SmithOla NordmannLanggt 234000 StavangerNorway
Empire BurlesqueSpecial Edition110.90
Hide your heart
19.90
Example XML
8/8/2019 Web Tech Class 7
42/47
42
Example XSLSchema
8/8/2019 Web Tech Class 7
43/47
43
Browser Architecture
Web Browser Architecture
8/8/2019 Web Tech Class 7
44/47
44
Browser Architecture (Contd)
It comprises eight major subsystems plus the dependencies between
them:
(1) The User Interface subsystem is the layer between the user andthe Browser Engine. It provides features such as toolbars, visualpage-load progress, smart download handling, preferences, and
printing. It may be integrated with the desktop environment toprovide browser session management or communication with otherdesktop applications.
(2) The Browser Engine subsystem is an embeddable component that
provides a high-level interface to the Rendering Engine. It loads a
given URI and supports primitive browsing actions such as forward,
back, and reload. It provides hooks for viewing various aspects of
the browsing session such as current page load progress and
JavaScript alerts. It also allows the querying and manipulation of
Rendering Engine settings.
B A hit t (C td )
8/8/2019 Web Tech Class 7
45/47
45
Browser Architecture (Contd..)(3) The Rendering Engine subsystem produces a visual
representation for a given URI. It is capable of displaying HTML and
Extensible Markup Language (XML) (Bray et al., 2004) documents,optionally styled with CSS, as well as embedded content such asimages. It calculates the exact page layout and may use reflowalgorithms to incrementally adjust the position of elements on thepage. This subsystem also includes the HTML parser.
(4) The Networking subsystem implements file transfer protocols suchas HTTP and FTP. It translates between different character sets,and resolves MIME media types for files. It may implement a cacheof recently retrieved resources.
(5) The JavaScript Interpreter evaluates JavaScript (also known asECMAScript) code, which may be embedded in web pages.JavaScript is an object-oriented scripting language developed byNetscape. Certain Java-Script functionality, such as the opening ofpop-up windows, may be disabled by the Browser Engine orRendering Engine for security purposes.
8/8/2019 Web Tech Class 7
46/47
46
Browser Architecture (Contd..)
(6) The XML Parsersubsystem parses XML documents into a
Document Object Model (DOM) tree. This is one of the mostreusable subsystems in the architecture. In fact, almost all browserimplementations leverage an existing XML Parser rather thancreating their own from scratch.
(7) The Display Backend subsystem provides drawing and windowingprimitives, a set of user interface widgets, and a set of fonts. It maybe tied closely with the operating system.
(8) The Data Persistence subsystem stores various data associatedwith the browsing session on disk. This may be high-level data such
as bookmarks or toolbar settings, or it may be low-level data such ascookies, security certificates, or cache.
8/8/2019 Web Tech Class 7
47/47
47