0% found this document useful (0 votes)
15 views10 pages

WAD Notes Unit2 Part II

XML (Extensible Markup Language) is a markup language designed for storing and transporting data in a human-readable and machine-readable format, allowing users to define their own tags. It is widely used for data transport, web services, configuration files, and document storage, and can be validated using DTD or XML Schema. XSLT is used for transforming XML documents into various formats, while modern programming frameworks enhance data binding and dynamic content manipulation in web applications.

Uploaded by

diksha.020264
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)
15 views10 pages

WAD Notes Unit2 Part II

XML (Extensible Markup Language) is a markup language designed for storing and transporting data in a human-readable and machine-readable format, allowing users to define their own tags. It is widely used for data transport, web services, configuration files, and document storage, and can be validated using DTD or XML Schema. XSLT is used for transforming XML documents into various formats, while modern programming frameworks enhance data binding and dynamic content manipulation in web applications.

Uploaded by

diksha.020264
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

Introduction to XML (Extensible Markup Language)

XML is a markup language, much like HTML, but its primary purpose is to store and transport data,
not to display it. It defines a set of rules for encoding documents in a format that is both human-
readable and machine-readable. The "Extensible" part means that the language has no predefined
tags. Instead, you define your own tags to describe the data's structure and meaning.

Simple XML Example

A simple XML document storing book information might look like this:

XML

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

<bookstore>

<book category="fiction">

<title lang="en">The Lord of the Rings</title>

<author>J.R.R. Tolkien</author>

<price>22.99</price>

</book>

<book category="computing">

<title lang="en">Learning XML</title>

<author>Erik T. Ray</author>

<price>39.95</price>

</book>

</bookstore>

Uses of XML

XML has become an essential technology for data handling across various platforms due to its
simplicity, generality, and usability over the Internet. Its primary uses include:

• Data Transport and Exchange: XML is the standard format for exchanging data between
different systems, databases, and applications, even those with different data formats.

• Web Services: Protocols like SOAP and architectures like REST often use XML to format the
data being sent between a server and a client.

• Configuration Files: Many software applications use XML files to store configuration and
settings.
• Document Storage: XML's structure makes it ideal for storing structured data like
documents, which can then be easily searched and manipulated.

• New Markup Languages: XML is used to create other domain-specific markup languages
(e.g., XHTML, SVG for graphics, and MathML for mathematical notation).

XML Key Components

A well-formed XML document adheres to fundamental syntax rules and is composed of several key
components:

Component Description Example

The optional beginning of the XML


document. It includes the XML <?xml version="1.0"
Prolog
declaration and the optional DOCTYPE encoding="UTF-8"?>
declaration.

Specifies the XML version and the


XML <?xml version="1.0"
character encoding used. It must be the
Declaration encoding="UTF-8"?>
first line if present.

The building blocks of an XML


document. Elements are defined by a
Elements <title>Learning XML</title>
starting tag, an ending tag, and the
content in between.

Used to mark up elements. They are


<bookstore> (start tag) and
Tags case-sensitive and must be properly
</bookstore> (end tag)
nested.

Provide extra information about an


Attributes <book **category="fiction"**>
element, specified within the start tag.

Root The single element that encloses all <bookstore>...</bookstore> in


Element other elements in the XML document. the example above.

DTD and Schemas (XML Validation)

To ensure that an XML document follows a specific structure and vocabulary, it can be validated
against a definition. The two main ways to define and validate the structure are Document Type
Definition (DTD) and XML Schema Definition (XSD).
Document Type Definition (DTD)

• Syntax: Uses a non-XML syntax.

• Function: Defines the legal building blocks of an XML document, including the elements,
attributes, entities, and their relationships.

• Limitation: Does not support data types (e.g., forcing a value to be an integer or a date) or
XML Namespaces.

XML Schemas (XSD)

• Syntax: Written in XML syntax itself, making it more extensible and parsable.

• Function: Defines the structure of the XML document and specifies data types (e.g.,
xs:string, xs:integer, xs:date) for elements and attributes.

• Advantage: Offers greater control, supports object-oriented concepts, and uses Namespaces
to avoid naming conflicts. XSD is the more modern and preferred method for validation.

Feature DTD XML Schema (XSD)

Syntax Non-XML syntax XML syntax

Data Types No support for complex data types Extensive support for data types

Namespaces No support Full support

Extensibility Limited Highly extensible

Using XML with Application

Applications interact with XML documents primarily by using an XML Parser. The parser reads the
XML document and provides an interface to access its data. There are two main approaches:

1. DOM (Document Object Model): The parser loads the entire XML document into memory
and represents it as a tree structure (a node-tree). This allows for easy access, modification,
addition, or deletion of elements. It is memory-intensive for large documents.

2. SAX (Simple API for XML): An event-driven parser that reads the XML document
sequentially, triggering events (like "start of element," "end of element," "text data") as it
encounters them. It is fast and memory-efficient for large documents, but it cannot modify
the document or easily jump around in the structure.

Modern programming languages and frameworks provide built-in libraries and APIs (like JAXP in Java,
or the built-in XML libraries in Python, C#, etc.) to handle both DOM and SAX parsing, enabling
applications to read data from, and write data to, XML documents.
Transforming XML using XSL and XSLT

XML transformation is the process of converting an XML document into another format, which can
be another XML document, HTML, or plain text. This is primarily done using XSLT.

XSL (Extensible Stylesheet Language)

XSL is a family of recommendations for transforming and rendering XML documents. It consists of
three parts:

1. XSLT (XSL Transformations): The primary language for transforming XML documents.

2. XPath (XML Path Language): A language used by XSLT to navigate and select nodes
(elements, attributes, etc.) from an XML document.

3. XSL-FO (XSL Formatting Objects): A vocabulary for specifying formatting semantics (how the
document should look, like page breaks and layouts).

XSLT (XSL Transformations)

XSLT is an XML-based language used to define rules for transforming an XML source document into a
new document.

• Mechanism: An XSLT stylesheet (which is itself an XML document) contains templates that
define how to match and transform nodes from the source XML tree into a result tree.

• Process: An XSLT processor takes the source XML document and the XSLT stylesheet as input
and produces the result document.

• Common Use Cases:

o XML to HTML: Transforming raw XML data into a format that can be displayed by a
web browser.

o XML to XML: Converting an XML document conforming to one schema into an XML
document conforming to a different schema (for data exchange).

o XML to Text: Generating reports, CSV files, or configuration files.

XSLT Transformation Example Flow

1. Source XML Data: Contains the structured data.

2. XSLT Stylesheet: Contains the transformation rules (templates) and uses XPath to select data.

3. XSLT Processor: Combines the XML data and the XSLT stylesheet.

4. Result Output: A new document (e.g., HTML, Text, or different XML).

Dynamic HTML (DHTML) is an umbrella term for a collection of technologies used together to create
interactive and animated web pages. It is not a single technology but a combination of HTML,
Cascading Style Sheets (CSS), and a scripting language (most commonly JavaScript) that allows the
content, style, and position of elements on a web page to be changed dynamically (in response to
user actions or other events) after the page has been loaded.

Here is a detailed breakdown of the components you mentioned:


Document Object Model (DOM) - Accessing HTML & CSS

The Document Object Model (DOM) is a programming interface for HTML and XML documents. It
represents the page so that programs can change the document structure, style, and content. The
browser creates a tree-like structure, or DOM tree, where every element, attribute, and piece of text
in the HTML document is represented as an object, or node.

• Accessing the DOM: Scripting languages like JavaScript interact with the DOM to make a
page "dynamic."

o Nodes: The DOM treats the HTML document as a hierarchy of nodes. There are
different types of nodes, such as Element nodes (e.g., <div>, <p>), Attribute nodes
(e.g., id="main"), and Text nodes (the content inside elements).

o Methods: JavaScript provides methods to find, navigate, and manipulate these


nodes. For example:

▪ [Link]('myId') to find an element.

▪ [Link] to get or set the HTML content of an element.

▪ [Link]('class', 'new-style') to change an element's attribute.

• DCOM (Component Object Model): The term DCOM (Distributed Component Object Model)
is a Microsoft-specific historical term related to how Windows and Internet Explorer
implemented object models, which included the DOM. While DCOM itself is largely obsolete
in modern web standards, the underlying concept it represented in this context—that of
programmatically accessing and manipulating document elements—is still central to the
modern, W3C-standard DOM.

Dynamic Content, Styles, and Positioning

Dynamic HTML is based on using the DOM and JavaScript to modify the three core aspects of the
web page:

• Dynamic Content (HTML): You can add, delete, or change any HTML element or the text
content within it. This allows you to update information on the page without requiring a full
page reload from the server.

o Example: Updating the score on a game page, or showing a "Thank You" message
after a form submission.

• Dynamic Styles (CSS): You can change the appearance of any element by modifying its CSS
properties through JavaScript.

o Example: Changing the color, font size, or background of an element when a user
hovers over it. You can do this by directly manipulating the style property (e.g.,
[Link] = 'red') or, more commonly, by changing the element's class
name (e.g., [Link] = 'highlight').
• Dynamic Positioning: You can change an element's position on the screen, enabling
animations and movement. This is typically done by modifying CSS positioning properties like
position, top, left, right, and bottom using JavaScript.

o Example: Creating a sliding menu panel or making an image move across the screen.

Event Bubbling

Event bubbling is a form of event propagation in the DOM. When an event (like a click) occurs on an
element, the event flow goes through three phases:

1. Capturing Phase: The event travels down from the window (root) to the target element.

2. Target Phase: The event reaches the actual element it originated on (the target).

3. Bubbling Phase (Default): The event then travels up from the target element back toward
the window, triggering any registered event handlers on its parent elements along the way.

• How it Works:

o If you click a <button> inside a <div>, the click event first triggers on the <button>.

o Then, it "bubbles up" to the parent <div>.

o It continues bubbling up to the <body>, the <html> element, and finally the
document object.

o If any of these ancestor elements have a click handler attached, that handler will
execute in the bubbling phase (unless the event is explicitly stopped).

• Event Delegation: Bubbling is essential for a technique called event delegation, where you
place a single event listener on a parent element to manage events for all its descendant
elements. This is highly efficient, especially for dynamic lists, as you don't need to add and
remove listeners for individual children.

Data Binding

Data binding is a technique that automatically synchronizes data between the data model (the
application's logic/data source) and the view (the HTML user interface). It eliminates the need for a
developer to manually write code to constantly update the UI whenever the data changes, or vice
versa.

• Early/Basic Data Binding (Plain DHTML): In basic DHTML, "data binding" involved manually
writing JavaScript to:

1. Get data from a source (e.g., an object or an array).

2. Use DOM manipulation methods (like [Link] = [Link]) to inject that


data into the HTML.

3. Manually attach event listeners (e.g., to an <input>) to update the data source when
the user changes the UI.
• Modern/Framework Data Binding (Key Concept): The concept has evolved significantly with
modern JavaScript frameworks (like React, Angular, and Vue), which offer advanced,
declarative data binding:

o One-Way Binding: Changes in the data model automatically update the view, but not
the other way around. This simplifies data flow and is common in rendering data
lists.

o Two-Way Binding: Changes in the data model automatically update the view, and
changes in the view (e.g., typing in an input field) automatically update the data
model. This is critical for forms and user inputs.

Data binding is what makes modern web applications feel instantly responsive and significantly
reduces the boilerplate DOM manipulation code a developer must write.

Extensible Markup Language (XML)

XML is a markup language for storing, transporting, and structuring data in a format that is both
human-readable and machine-readable.

Advantages Disadvantages

Verbose and Redundant: The use of


Self-Describing: Tags are not predefined (like in
opening and closing tags for all data leads
HTML) and provide information about the data,
to large file sizes compared to simpler
making the structure easy to understand.
data formats like JSON.

Platform and Language Independent: Can be Higher Storage and Transport Cost: Large
used across different systems, applications, and file sizes increase the cost for storage and
programming languages, simplifying data network transfer, especially for high-
exchange. volume data.

Data Separation: Separates data from its Parsing Overhead: Parsing XML
presentation (which is handled by other documents takes more time and resources
technologies like HTML/CSS/XSLT), allowing data than simpler formats due to its verbose
to be changed without affecting presentation. nature and required validation steps.

Does Not Directly Support Arrays:


Represents arrays using nested elements,
Supports Complex Data: Accommodates
which can sometimes be less intuitive
complex, hierarchical data structures.
than native array support in other
formats.
Advantages Disadvantages

Can Be Overly Complex: Manually


Validation: Supports validation using DTDs
structuring large or deeply nested XML
(Document Type Definitions) and XML Schema,
can be challenging and complex to
ensuring data integrity.
maintain.

Extensible Stylesheet Language (XSL) and XSL Transformations (XSLT)

XSL is a family of recommendations for transforming and presenting XML documents. It has three
parts: XSLT (Transformation), XPath (Expression language for navigating an XML document), and XSL-
FO (Formatting Objects for print styling). XSLT is the core component for transformation.

Advantages of XSL/XSLT

• Separation of Concerns: Provides a clean way to separate XML data from its presentation
logic. A single XML source can be transformed into multiple formats (HTML, PDF, plain text,
other XML, etc.).

• Powerful Transformation: Designed specifically for XML data manipulation, making complex
data transformations concise and easier to implement than in a general-purpose
programming language.

• Declarative Paradigm: XSLT is a declarative language (you describe what you want, not how
to do it), which can lead to shorter, clearer code for many transformation tasks.

• W3C Standard: XSLT is a well-defined W3C recommendation, ensuring broad support and
interoperability across different implementations (processors).

• Code Reusability: Stylesheets (.xsl files) can be reused across multiple XML documents,
ensuring consistent transformations.

Disadvantages of XSL/XSLT

• Unfamiliar Programming Model: The declarative and template-based approach is often


unfamiliar and awkward for programmers used to procedural or object-oriented languages,
leading to a steep learning curve.

• Debugging Difficulty: Tracing and debugging complex XSLT stylesheets can be challenging, as
the flow is based on pattern matching and templates rather than a sequential program
execution.

• Performance and Memory: XSLT processors often load the entire XML document into
memory (the DOM tree) before transformation, which can be an issue for very large
documents and can consume significant memory. Modern versions (XSLT 3.0) offer streaming
to mitigate this, but it adds complexity.

• Verbosity: Since XSLT stylesheets are themselves written in XML, their syntax can be verbose
and hard to read, making complex logic difficult to comprehend at a glance.
• Client-Side Browser Support: Relying on client-side XSLT transformation is unreliable due to
inconsistent support and performance across different browsers, especially older ones, and
can hinder search engine indexing.

Dynamic HTML (DHTML)

DHTML is not a language but a collective term for a combination of web technologies—HTML
(structure), CSS (style), and Client-Side Scripting (like JavaScript) with the DOM (behavior)—used to
create web pages with dynamic effects and interactivity on the client side without needing to reload
the page.

Advantages Disadvantages

Enhanced Interactivity: Allows for Browser Compatibility Issues (Historically):


rich, dynamic user interfaces, Different browsers historically had different
animations, and real-time content implementations of the DOM and JavaScript,
changes without server requests (e.g., leading to "write once, test everywhere" issues. This
drop-down menus, mouse-over is less of a problem now but still requires careful
effects). coding.

Faster Load Times (Client-Side


Processing): Reduces server requests, Steep Learning Curve: Requires the developer to be
saving bandwidth and allowing proficient in multiple technologies: HTML, CSS,
content updates to happen instantly JavaScript, and understanding the DOM.
on the client machine.

Reduced Server Load: By handling Potential for Code Complexity: Combining multiple
interactivity on the client side, the technologies can result in long, complex code that is
server is freed from generating new difficult to maintain and debug, especially for large
pages for every user action. applications.

No Extra Plugins Needed: Utilizes


Security Risks: Client-side scripting is vulnerable to
technologies native to the web
attacks like Cross-Site Scripting (XSS) if not handled
browser, eliminating the need for
properly.
users to install external plugins.

Document Object Model (DOM)

The DOM is a cross-platform, language-independent programming interface that treats an HTML or


XML document as a tree structure, where each node is an object representing a part of the
document (element, text, attribute, etc.). It allows scripts (like JavaScript) to dynamically access and
manipulate the content, structure, and style of a document.
Advantages Disadvantages

Dynamic Content Manipulation:


Provides a standardized API to access Memory Consumption: Loading the entire
and modify a web page's content, document into a tree structure in memory can be
structure, and style in real-time after inefficient and consume significant resources for
the page has loaded, enabling rich very large documents.
interactivity.

Language and Platform Neutral: The Performance Overhead (Reflows/Repaints):


DOM is a standard API and can be Frequent or poorly executed DOM manipulation
accessed and manipulated using any can be slow. Changes to the DOM often trigger a
compatible programming language costly reflow (recalculating element positions) or
(most commonly JavaScript). repaint (redrawing elements) of the page.

Standardized Access: Provides a Synchronization Overhead: Since the DOM is a


common, hierarchical structure for all live representation of the document, changes
web pages (W3C standard), ensuring made by scripts are immediately reflected, which
consistent interaction with page can cause performance issues if updates are not
elements across different browsers. batched or optimized.

Foundation for Modern Frameworks:


Initial Page Load Time: The browser needs to
Essential for modern web development,
construct the full DOM tree before it can fully
serving as the basis for how front-end
render the page and execute scripts that depend
frameworks (like React, Vue, Angular)
on it, potentially slowing the initial display.
manage and update the user interface.

You might also like