0% found this document useful (0 votes)
17 views40 pages

WK 05 XML

The document provides an overview of eXtensible Markup Language (XML), highlighting its purpose to focus on content rather than presentation, and its flexibility in allowing developers to define custom tags. It discusses various applications of XML, such as data exchange, web searching, document formatting, and configuration files, while also addressing its limitations like verbosity and lack of built-in security features. Additionally, the document covers XML validation, schema definitions, and examples of XML and XML Schema Definition (XSD).

Uploaded by

Gaming Kimg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views40 pages

WK 05 XML

The document provides an overview of eXtensible Markup Language (XML), highlighting its purpose to focus on content rather than presentation, and its flexibility in allowing developers to define custom tags. It discusses various applications of XML, such as data exchange, web searching, document formatting, and configuration files, while also addressing its limitations like verbosity and lack of built-in security features. Additionally, the document covers XML validation, schema definitions, and examples of XML and XML Schema Definition (XSD).

Uploaded by

Gaming Kimg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Web Technology

eXtensible Markup Language

Dr. Navanath Saharia


Indian Institute of Information Technology Senapati, Manipur

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 1 / 40
XML Why XML?

Why XML?
❂ HTML has grown into a huge and complex language
✍ The prime objective of HTML is somehow compromised as several tags, such as <font>,
<span>, and <div> are introduced for presentation rather than the content. Thus bulky, more
than 100 fixed tags. On the other hand, domain specific content such as music, e-commerce and
mathematics are still not sufficient to represent.
❂ HTML does a good job by separating the content and presentation
✍ Logically structured, but semantic annotations are missing.
✍ HTML documents are search-able, Searching performance is poor due to absence of semantic
mapping
❂ XML aims to focus on the content rather than the appearance of the documents.
✍ Resolve the conflicting demands on tags: on one hand, specialized applications need more tags;
on the other hand, many tags are not frequently used and can be removed.
❂ To meet the above objectives XML adapts the following principles
✍ XML has no pre-defined tags. Developers are free to define application specific tags. Hence,
XML is flexible and extensible.
✍ XML has strict syntax. Thus, XML browsers are smaller, lighter and. . faster.
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 2 / 40
XML Applications of XML

Application of XML
❂ XML is platform-independent, computer-language-neutral and text-based data exchange mechanism,
which facilitates exchanging of data between two computer systems. Thus, forming a backbone for
automatic communications for e-commerce stack-holders, such as product-selection-portal (flipkart,
amazon), payment-gateway (BillDesk, PayU, CCAvenue, JusPay), and supply/distribution-chain,
scientific and entertainment medium and devices.
❂ Web searching and automating Web tasks: XML defines the type of information contained in a
document, making it easier to return useful results when searching the Web. For example, using
HTML to search for books authored by Tom brown is likely to return instances of the term ’brown’
outside of the context of author. Using XML restricts the search to the correct context (for example,
the information contained in the <author> tag) and returns only the information that an user want.
❂ Document Formatting: Open a .docx document with text-editor and check the structure
❂ Configuration files: Used to store configuration information for software applications as it is
platform-neutral unlike databases.
❂ Rich Internet Applications: Used to build Rich Internet Applications that can run in web browsers.
Example: Online Games, Social Media Applications . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 3 / 40
XML Example

My first XML
<?xml version="1.0"?>
<courseDetails>
<course id="CS2015">
<name>Web Technology</name>
<credit>8</credit>
<instructor>Dr. N. Saharia</instructor>
</course>
<course id="CS2043">
<name>Database Management Systems</name>
<credit>6</credit>
<instructor>Dr. R. B. Devi</instructor>
</course>
<course id="CS2022">
<name>Theory of Computing</name>
<credit>6</credit>
<instructor>Dr. K. M. Singh</instructor>
</course>
<courseDetails>
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 4 / 40
XML Example

Experiment with well-formedness

<?xml version="1.0"?>
<bookLib>
<book>
<title>Database systems</title>
<author>Hector Garcia-Molina</author>
<isbn>135-383-9038</isbn>
<price>800</price>
<note>The price range is > 500 & < 1000 INR</note>
</book>
<bookLib>

Solution to the error lies in &amp; &gt; &lt; &apos; &quote;


<note> The price range is &gt; 50 &amp; \&lt; 800 INR</note>

Well-formed-ness of markup nomenclature → Can’t start with digit


. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 5 / 40
XML Limitations

Limitations

❂ XML documents tend to be verbose and can become very large, making them difficult to read, store
and transmit.

❂ XML requires a strict adherence to a specific structure, and validating an XML document against a
schema can be time-consuming and complicated.

❂ Slow, especially when dealing with large files, which can effect performance.

❂ Being a markup language, it does not include built-in functionality for tasks such as data
manipulation and transformations, which requires additional software.

❂ XML does not have built-in security features, such as encryption or authentication, and must rely on
other technologies for security.

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 6 / 40
XML XML Validation

XML Validation

❂ A process by which an XML document is validated.


❂ An XML document is said to be valid if its contents match with the
✍ Element
✏ Basic building block of the XML document
✏ Used as a container to store text, attributes, media objects etc.
✍ Attribute
✏ Identifier associated with an XML tag.
✏ It has a unique name in the context of the tag, and a string value.
✍ Schema - Defines the structure, legal elements and attributes of an XML document.
❂ Two ways to perform validation
✍ Well-formedness - Adheres to the XML syntax rules
✍ Valid XML - Process of determining whether the structure, content, and data types of an XML
document are valid
❂ Only the valid documents are valuable in terms of sharing and retrieving information.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 7 / 40
XML XML Schema

XML Schema
❂ Specification that defines a way to describe the structure and constraints of the building blocks, such
as, elements, attributes, and data types of an XML document.
❂ Thus, XML Schema is used to define the rules that an XML document must adhere to in order to be
considered valid. Few languages developed specifically to express and design XML schema.
❂ Example: Document Type Definition (DTD), XML Schema Definition (XSD), REgular LAnguage
for XML Next Generation (RelaxNG), Schematron, Schema for Object-Oriented XML (SOX)
❂ Use of XML Schema
✍ Primary uses is to validate XML document.
✍ XML schema is used as a interface between different web services, to validate incoming and
outgoing messages. Web Services Description Language (WSDL) is an XML-based language
that describes the interface and operations of a web service.
✍ Provides a formal specification of the elements, attributes, and data types used in an XML
document, which is valuable for developers, data analysts, and other stakeholders who need to
understand the structure and constraints of the XML data.
✍ XML Schema can be used in conjunction with XSLT (eXtensible Stylesheet Language
Transformations) to transform XML data from one format to another . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 8 / 40
XML Schema XSD

XSD : XML Schema Definition


❂ A XML schema language (written in XML) used to specify how to describe the component of an
XML document. It is used to define the building blocks of an XML document, including:
✍ Attributes and elements
✍ The number and order of child elements
✍ Data types of elements and attributes, and
✍ Default and fixed values for elements and attributes.
❂ Element: An element is the building block of an XML document and is defined within the XSD. Can
be classified into three class - simpleType, complexType and anyType/globalType
✍ Syntax: <xs:element name = "abc" type = "bcd"/>
✍ Example: <xs:element name="title" type="xs:string" />
✍ Simple type element specifies only text. It cannot have attributes and elements
✍ Complex type element can contain text, elements, and attributes
✍ Any type element specifies that any well-formed XML is allowed in its place in XML instance
✍ An element can be considered as valid without content if it has the attribute xsi:nil with the
value true.
❂ XSD supports the use of namespaces, enabling the creation of modular and extensible schemas.
❂ Namespace helps to avoid naming conflicts when multiple schemas are used. . together
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 9 / 40
XML Schema XSD

XSD Datatype

XSD Primitive Datatype


❂ anyURI: Represents an Internationalized Resource
Identifier Reference, where value can be absolute or
relative, and may have an optional fragment identifier
❂ string: Represents character sequence
✍ normalizedString datatype is derived from string
[Strings that do not contain the carriage return
(#xD), line feed (#xA) nor tab (#x9) characters]
✍ token → normalizedString that represents
tokenized strings. [strings that do not contain
#xD, #xA, #x9 and #x20]
✍ language, NMTOKEN, name → token
❂ hexBinary: Represents hex-encoded binary data.
❂ base64Binary: Represents Base64-encoded binary data
Image source: https://www.w3.org/TR/2012/ . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected]
REC-xmlschema11-2-20120405/datatypes.html eXtensible Markup Language 10 / 40
XML Schema XSD

XSD Primitive Datatype


❂ boolean: Represents the values of two-valued logic
❂ decimal: Represents a subset of the real numbers that can be obtained by dividing an integer by a
non-negative power of ten.
✍ integer → decimal
✍ nonPositiveInteger, long (int, short, byte → long), nonNegativeInteger
(unsignedLong, unsignedInt, unsignedShort, unsignedByte → nonNegativeInteger)
datatypes are derived from integer
❂ float: Patterned after the IEEE single-precision 32-bit floating point datatype
❂ double: Patterned after the IEEE double-precision 64-bit floating point datatype
❂ duration: Represents durations of time
✍ yearMonthDuration, dayTimeDuration → duration
❂ dateTime: Represents instants of time with timezone
✍ dateTimeStamp datatype is derived from dateTime datatype.
❂ time: Represents instants of time that recur at the same point in each calendar day
❂ date: Represents instants of date in a calendar. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 11 / 40
XML Schema XSD

XML Schema example

<?xml version="1.0" encoding="UTF-8"?>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="author" type="xs:string" />
<xs:element name="isbn" type="xs:string" default="81-"/>
<xs:element name="price" type="xs:decimal" default = "500.00"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 12 / 40
XML Schema Document Type Declaration

Document Type Declaration


❂ Used to declare the building blocks of an XML document
❂ DTD defines:
✍ A structure of the XML document
✍ A list of legal elements of the XML document
✏ Elements, Tag, Attribute, Entity, #PCDATA, and CDATA
❂ Example

<?xml version="1.0"?>
<!DOCTYPE bookLib
<bookLib>
[
<book>
<!ELEMENT book(title,author,isbn)>
<title>Database systems</title>
<!ELEMENT title (#PCDATA)>
<author>Hector Garcia-Molina</author>
<!ELEMENT author (#PCDATA)>
<isbn>135-383-9038</isbn>
<!ELEMENT price (#PCDATA)>
<price>800</price>
]
</book>
>
<bookLib> . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 13 / 40
XML Schema Types of DTD

Types of DTD

❂ External - Separate definition file linked with URI. External DTD does not require DOCTYPE
<!-- book.dtd -->
<!ELEMENT book (#PCDATA)>
<!-- In XML -->
<?xml version="1.0"?>
<!DOCTYPE bookLib SYSTEM "book.dtd"> ...

❂ Internal - Document definitions are embedded in parent file


<?xml version="1.0"?>
<!DOCTYPE bookLib [<!ELEMENT book (title,author,isbn)> <!ELEMENT title (#PCDATA)>
!→ <!ELEMENT author (#PCDATA)> <!ELEMENT isbn (#PCDATA)>]>
<bookLib><book><title>Database systems</title><author>Hector
!→ Garcia-Molina</author><isbn>135-383-9038</isbn></book></bookLib>

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 14 / 40
XML Schema Types of DTD

String replacement

❂ Syntax to define shortcuts to common text


<!ENTITY entity-name "entity-value">

❂ Example in DTD:
<!ENTITY organization "IIIT Manipur">
<!ENTITY copyright “&#xA9;”>

❂ In XML
<author>&copyright; &organization;</author>

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 15 / 40
XML Schema Declaring Attributes

Declaring Attributes in DTD

❂ XML element attributes are declared with an ATTLIST declaration. An attribute declaration has the
following syntax:
❂ Syntax <!ATTLIST element-name attribute-name attribute-type default-value>

❂ DTD Example
<!ELEMENT book EMPTY>
<!ATTLIST book edition CDATA "1">

❂ XML example:
<book edition="1"></book>

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 16 / 40
XML Schema PCDATA

PCDATA

❂ PCDATA → Parse-able character data → text that will be parsed by a parser


❂ XML parser examine the data and ensure that it does not content entity if it contains that will be
replaced.

<?xml version="1.0"?>
<!DOCTYPE book SYSTEM "book.dtd">

<bookLib>
<book>
<title>Database systems</title>
<author>Hector Garcia-Molina</author>
<isbn>135-383-9038</isbn>
</book>
</bookLib>
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 17 / 40
XML Schema CDATA

CDATA

❂ CDATA → Character data → Texts, which will not be parsed further


❂ A CDATA section is used to mark a section of an XML document, so that the XML parser interprets
it only as character data, and not as markup.
❂ It is useful when one XML data need to be embedded within another XML document.

<?xml version="1.0"?>
<bookLib>
<![CDATA[
<book>
<title>Database systems</title>
<author>Hector Garcia-Molina</author>
<isbn>135-383-9038</isbn>
</book>
]]>
</bookLib>
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 18 / 40
XML Schema Nested entity

Nested entity/element
❂ XML element that may contain one or more elements. An element that contains another element is
called as parent, and the contained element is the child.
❂ In DTD, the children are declared in a sequence, the way they appear in the XML document
separated by comma
❂ A child may also has children. DTD for an element with children looks like:
<!ELEMENT email (to,from,subject,message)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT subject (#PCDATA)>
<!ELEMENT message (#PCDATA)>
❂ Counting the occurrences of the nested entities
✍ Only one occurrence of the same element <!ELEMENT email (message, #PCDATA)>
✍ Minimum one occurrence of the same element <!ELEMENT email (message+)>
✍ Zero or more occurrences of the same element <!ELEMENT email (message*)>
✍ Zero or one occurrences of the same element <!ELEMENT email (message?)>
✍ Combining all <!ELEMENT email (to+, from,
. . . .message*,
. . . . . . . . #PCDATA)>
. . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 19 / 40
XML Schema Formal Public Identifier

Revisiting URI

❂ What is URI?
✍ A sequence characters that is used to identify a particular resource
uniquely
❂ How URL is different from URI?
✍ URL is a type of URI that provides the means to locate and retrieve a
resource by specifying its location, typically on the internet, however, URI
is a generic term for identifying resources. URI usage URL or URN to
identify a required resource.
❂ What is URN?
✍ A type of URI that is used to uniquely identify a resource by name in a
particular namespace. For example: Image source:
✏ urn:iso:std:iso:3166:-1 → Identifies codes for the names of countries https://en.wikipedia.org/
wiki/ISBN#/media/File:
✏ urn:doi:10.1000/123456 → Identifies digital content uniquely ISBN_Details.svg
✏ urn:isbn:0451450523 → Identifying a book by its ISBN
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 20 / 40
XML Schema Formal Public Identifier

Formal Public Identifier (FPI)


❂ A piece of formatted text that may be used to uniquely identify a product, specification or document.
❂ FPI is used to identify and reference a particular version of DTD/ specification uniquely.
✍ -//W3C//DTD XHTML 1.0 Transitional//EN → DTD for XHTML 1.0 specified by the W3C
✍ -//W3C//DTD MathML 2.0//EN → DTD for representing mathematical notation in markup.
✍ -//TEI//DTD P4//EN → DTD for TEI used for encoding and interchange of humanities texts
✍ -//WHATWG//NONSGML HTML5//EN
❂ Syntax: <approved or not> // <owner-identifier> // <text-identifier> // <language>
❂ Made-up of four fields, each separated by double forward slashes (//)
1st field - Indicates whether the DTD is connected to a formal standard or not.
(-) indicates DTD has not been approved.
(+) indicates DTD has been approved by a non-standard body.
(standard’s name) indicates approved by a formal standard body
2nd field W3C Holds the name of the group (or person) responsible for the DTD
3rd field DTD Indicates the type of document that is being described, usually contains
XHTML 1.0 some form of unique identifier including the version number
Transitional
4th field EN Indicates the language that the DTD uses. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 21 / 40
XML Schema Formal Public Identifier

Use of FPI

❂ General Syntax: <!DOCTYPE rootname [PUBLIC | System] FPI (optional) URL>

❂ Using PUBLIC
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
!→ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

❂ Using SYSTEM
<!DOCTYPE rootElement SYSTEM
!→ "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd">

❂ rootElement may be html or any other root element in XML, such as <bookLib>

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 22 / 40
XSL eXtensible Stylesheet Language

eXtensible Stylesheet Language (XSL)

❂ A server side styling language, that is used to transform XML documents into other document types
and to format the output, as opposed to CSS.

❂ Declaration in the XSL file (book.xsl)


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
or
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

❂ Linking the XSL file with the XML (book.xml)


<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>

❂ Uses XPATH for navigation and XQuery for retrieval


. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 23 / 40
XSL Component of XSL

Component of XSL

❂ An XSLT style-sheet comprises of XSLT elements and attributes.


✍ Common XSLT elements include <xsl:template>, <xsl:apply-templates>, <xsl:for-each>,
<xsl:value-of>, <xsl:if>, <xsl:sort>, <xsl:choose>, <xsl:when>, <xsl:otherwise> etc.
❂ Select one or more nodes for transformation
❂ A node could be - elements, attributes, text, namespaces, processing-instructions, and comments.
❂ To select a component use match attribute with <xsl:template>. <xsl:template match="/">
❂ <xsl:apply-templates/> determines where the content of its children appear on the transformed
document.
❂ <xsl:value-of select="name of node"/> select the node from where data to be retrieve
<xsl:template match="bookLib">
<xsl:for-each select="name">
<xsl:value-of select="."/><xsl:element name="br"/>
</xsl:for-each>
</xsl:template>
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 24 / 40
XSL Example

Example of XSL: book.xml


<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="book.xsl"?>
<bookLib>
<book edition="1">
<title>Database systems</title>
<author>Hector Garcia-Molina</author>
<isbn>135-383-9038</isbn>
</book>
<book edition="2">
<title>Fundamentals of Database Systems</title>
<author>Ramez Elmasri and Shamkant B. Navathe</author>
<isbn>9780-1360-8620-8</isbn>
</book>
<book edition="2">
<title>Introduction to Cryptography</title>
<author>Wade Trappe and Lawrence C. Washington</author>
<isbn>9788-1317-1476-8</isbn>
</book>
</bookLib> . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 25 / 40
XSL Example

Example of XSL : book.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> <body> <h3>Book Details</h3>
<table border="1">
<tr><th>Title</th> <th>Author</th></tr>
<xsl:for-each select="bookLib/book">
<tr> <td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td></tr>
</xsl:for-each>
</table> </body> </html>
</xsl:template>
</xsl:stylesheet>
As XSLT is server side styling language, place the book.xsl and book.xml file inside
\var\www\html before browsing the book.xml file using http://localhost/book.xml
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 26 / 40
XSL Example

Example of XSL: book-div.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><style>
.contentBox {background-color: white; border: 2px double green; border-radius: 5px;
!→ text-align: center; text-decoration: none; display: inline-block; margin: 4px 2px;
!→ padding: 16px 32px;}
.contentBox:hover {background-color: green; color: white;}
</style></head><body>
<xsl:for-each select="bookLib/book">
<p class="contentBox">
<span style="font-size: 2vw;"><xsl:value-of select="title"/></span><br/>
<span style="font-size: 1vw;"><xsl:value-of select="author"/></span><br/>
<span style="font-size: 1vw;"><xsl:value-of select="isbn"/></span>
</p> </xsl:for-each>
</body></html>
</xsl:template>
</xsl:stylesheet> . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 27 / 40
XSL Server Side Transformation

Transforming XML to HTML using XSL in PHP

❂ Delete <?xml-stylesheet type="text/xsl" href="book.xsl"?> from book.xml file. Now the XML
file is free from reference.
❂ Create a file book.php in the path \var\www\html and add the following content

<?php
$xml = new DOMDocument;
$xml->load('book.xml');
$xsl = new DOMDocument;
$xsl->load('book.xsl');
$xslt = new XSLTProcessor;
$xslt->importStyleSheet($xsl);
echo $xslt->transformToXML($xml);
?>

❂ Browse the book.php file using http://localhost/book.php


Example source: W3Schools (https://www.w3schools.com/xml/xsl_server.asp)
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 28 / 40
XSL Client Side Transformation

Transforming XML to XHTML using XSL in Java Scipt


❂ Delete <?xml-stylesheet type="text/xsl" href="book.xsl"?> from book.xml file. Now the XML
file is free from reference.
❂ Create a file book.xhtml in the path \var\www\html and add the following content
<!DOCTYPE html><html><head><script>
function loadXMLDoc(filename){
if (window.ActiveXObject) {xhttp = new ActiveXObject("Msxml2.XMLHTTP");}
else{xhttp = new XMLHttpRequest();}
xhttp.open("GET", filename, false);
try {xhttp.responseType = "msxml-document"} catch(err) {} xhttp.send(""); return xhttp.responseXML;
}
function displayResult(){
xml = loadXMLDoc("book.xml");
xsl = loadXMLDoc("book-div.xsl");
if (window.ActiveXObject || xhttp.responseType == "msxml-document"){ex = xml.transformNode(xsl);
document.getElementById("example").innerHTML = ex;}
else if (document.implementation && document.implementation.createDocument){
xsltProcessor = new XSLTProcessor(); xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml, document);
document.getElementById("example").appendChild(resultDocument);}
}
</script></head><body onload="displayResult()"><div id="example" /></body></html>

❂ Browse the book.xhtml file


. . . . . . . . . . . . . . . . . . . .
Example source: W3Schools (https://www.w3schools.com/xml/xsl_client.asp)
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 29 / 40
XSL Sorting values

Sorting values of an element

❂ <xsl:sort> is used to sort the output of the <xsl:for-each> element


<xsl:template match="bookLib">
<xsl:for-each select="book">
<xsl:sort select="name"/>
<xsl:value-of select="name"/>
<xsl:element name="br"/>
</xsl:for-each>
</xsl:template>

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 30 / 40
XSL Condition-based retrieval

Condition-based retrieval

❂ <xsl:if> is used to perform conditional rendering against the contents


<xsl:for-each select="book">
<xsl:if test="@edition = '1'">
<tr style="background-color: blue;">
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="isbn"/></td>
</tr>
</xsl:if>

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 31 / 40
XSL Choosing values from a set

Choosing values from a set


❂ < xsl : choose > is used to compare a value against a range of possible values
<xsl:for-each select="book">
<xsl:choose>
<xsl:when test="@edition = '1'">
<tr style="background-color: blue;">
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="author"/></td>
</tr>
</xsl:when>
<xsl:when test="@edition = '2'">
<tr style="background-color: red;">
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="author"/></td>
</tr>
</xsl:when>
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 32 / 40
XSL

General Functions
❂ current() - returns the value of the current node
<xsl:for-each select="bookLib/book/title">Current node: <xsl:value-of
!→ select="current()"/><br />
</xsl:for-each>
❂ function-available() - checks the whether the processor supports the function or not
<xsl:choose>
<xsl:when test="function-available('abs')"> <p>Function abs is available to
!→ use</p></xsl:when>
<xsl:otherwise><p>Function abs is not available to use</p></xsl:otherwise>
</xsl:choose>
❂ element-available() - checks the whether the processor supports the elements or not
<xsl:choose>
<xsl:when test="element-available('xsl:if')"> <p>Element xsl:if is supported
!→ by the prosessor</p></xsl:when>
<xsl:otherwise><p>Element xsl:if is not supported by the
!→ prosessor</p></xsl:otherwise></xsl:choose> . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 33 / 40
XSL Homework

Homework

❂ Display the name of the books whose price is less than 500

❂ Display the name of the books with highest price

❂ Display the name of the books with lowest price

❂ Display all book names published by the Pearson Publisher

❂ Display all the books written by ‘Andrew S Tanenbaum’

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 34 / 40
XSL Homework

XML + DTD + XSL = HTML

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 35 / 40
Services Web services

Web services
❂ Web services are a new breed of Web application. They are self-contained, self-describing, modular
applications that can be published, located, and invoked across the Web. Web services perform
functions, which can be anything from simple requests to complicated business processes...Once a
Web service is deployed, other applications (and other Web services) can discover and invoke the
deployed service.
❂ Web service provide an application integration technology that can be successfully used over the
internet
❂ web services development model with J2EE relies on the following four standard open technologies
✍ XML: The use of XML standards is very important in the overall scheme of the web services
universe.
✍ Java: A critical component of this is the Java API for XML Parsing (JAXP) . The future will
bring a few new JAX* APIs, mainly for dealing with the XML data formats and services. These
future JAX* API’s will allow for greater ease and speed in development.
✍ TCP/IP: The universal networking protocol. Everything from pagers to mobile phones to
laptops to mainframes can communicate through TCP/IP.
✍ HTML: The universal user interface. You can use HTML tags to render data on just about any
device you can think of. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 36 / 40
Services Web services

Web Service Standard

❂ Business Registry - Universal Description Discovery and Integration (UDDI) Before a partner can
make a web service call to a business, it must first locate a business with the service needed, discover
the call interface and semantics, and configure software on their end to collaborate with the service.
This will behave as a vehicle to publish web services.
❂ In another word A business registry standard for indexing web services, so that their descriptions can
be located by development tools and applications.
❂ Java APIs for XML Registries (JAXR) - to support the functionality of UDDI on the Java platform,
the JAXR is a API specification that developers can use to access registries.
❂ JAXP enables enterprise developers to add essential XML functionality to their Java applications, in
areas such as e-commerce, enterprise application integration, and dynamic web publishing,
❂ Web Services Description Language (WSDL) - for a business to discover a service it wants to use, it
needs to understand the call syntax and semantics prior to actually making a call.
❂ The WSDL specification is an XML document which describes the interface, semantics, and
administrative of a call to the web service.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 37 / 40
Services Implementation of Web services

Implementing web service

1 Service provider creates a web service


2 The service provider uses WSDL to describe the service to (UDDI registry).
3 The service provider registers the service (in a UDDI registry and /or ebXML registry or repository).
4 Another service or user locates and requests the registered service by querying UDDI and/or ebXML
registry(ies).
5 The requesting service or user writes an application to bind the registered service using SOAP(in the
case of UDDI) and/or ebxml.
6 Data and messages are exchanged as XML over HTTP.

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 38 / 40
Services Web of Services

Web of Services

1 Web of Services refers to message-based design frequently found on the Web and in enterprise
software. The Web of Services is based on technologies such as HTTP, XML, SOAP, WSDL,
SPARQL, and others.

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 39 / 40
Services Web of Services

Web of Devices

1 W3C is focusing on technologies to enable Web access anywhere, anytime, using any device. This
includes Web access from mobile phones and other mobile devices as well as use of Web technology in
consumer electronics, printers, interactive television, and even automobiles.

. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 40 / 40

You might also like