WK 05 XML
WK 05 XML
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[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
<?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>
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
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 Datatype
<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
<?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"> ...
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 14 / 40
XML Schema Types of DTD
String replacement
❂ Example in DTD:
<!ENTITY organization "IIIT Manipur">
<!ENTITY copyright “©”>
❂ In XML
<author>©right; &organization;</author>
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 15 / 40
XML Schema Declaring Attributes
❂ 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
<?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
<?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
Use of FPI
❂ 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
❂ 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.
Component of XSL
❂ 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);
?>
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 30 / 40
XSL Condition-based retrieval
Condition-based retrieval
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 31 / 40
XSL Choosing values from a set
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
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[email protected] eXtensible Markup Language 34 / 40
XSL Homework
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[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
❂ 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
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
[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