0% found this document useful (0 votes)
33 views

Examples of XML

The document discusses several markup languages and technologies including XML, HTML, CSS, XSLT, XPath, XQuery and more. Key topics covered include using DOM to access and manipulate HTML elements, dynamic content with JavaScript, styling content with CSS, transforming XML with XSLT, traversing XML with XPath and querying XML with XQuery.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Examples of XML

The document discusses several markup languages and technologies including XML, HTML, CSS, XSLT, XPath, XQuery and more. Key topics covered include using DOM to access and manipulate HTML elements, dynamic content with JavaScript, styling content with CSS, transforming XML with XSLT, traversing XML with XPath and querying XML with XQuery.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

XML

Example of XML
<?xml version = "1.0"?>
<bname>
<name>CBT</name>
<no>100</no>
<price>400</price>
</bname>

DOCUMENT OBJECT MODEL (DOM)


<!DOCTYPE html>
<html>
<body>
<h2>JavaScript HTML DOM</h2>
<div id="main">
<p>Finding HTML Elements by Tag Name</p>
<p>This example demonstrates the <b>getElementsByTagName</b> method.</p>
</div>
<p id="demo"></p>
<script>
const x = document.getElementById("main");
const y = x.getElementsByTagName("p");
document.getElementById("demo").innerHTML =
'The first paragraph (index 0) inside "main" is: ' + y[0].innerHTML
</script>
</body>
</html>
DYNAMIC HTML (HTML 4.0, CSS,JAVASCRIPT,DOM)
<HTML>
<head>
<title>
Method of a JavaScript
</title>
</head>
<body>
<script type="text/javascript">
document.write("JavaTpoint");
</script>
</body>
</html>

XSL (EXTENSIBLE STYLESHEET LANGUAGE)


Sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="example.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
</cd>
</catalog>
example.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>
<h2>Data Display using XSL </h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

XFORMS

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms">


<head>
<title>Hello World in XForms</title>
<xf:model>
<xf:instance xmlns="">
<data>
<PersonGivenName/>
</data>
</xf:instance>
</xf:model>
</head>
<body>
<p>Type your first name in the input box. <br/>
If you are running XForms, the output should be displayed in the output area.</p>
<xf:input ref="PersonGivenName" incremental="true">
<xf:label>Please enter your first name: </xf:label>
</xf:input>
<br />
<xf:output value="concat('Hello ', PersonGivenName, '. We hope you like XForms!')">
<xf:label>Output: </xf:label>
</xf:output>
</body>
</html>
OURPUT :
Type your first name in the input box.
If you are running XForms, the output should be displayed in the output area.
Please enter your first name:sample
Output: Hello sample We hope you like XForms!
XHTML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XHTML Example</title>
</head>
<body>
<p>This is an XHTML paragraph.</p>
</body></html>
OUTPUT :
This is an XHTML paragraph

XSLT (eXtensible Stylesheet Language Transformations)

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


<xsl:template match="/">
<html>
<body>
<h1>Hello World!</h1>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
OUTPUT :
Hello world!
XLINK

<a:href xmlns:a="http://www.w3.org/1999/xlink" xlink:type="simple">http://example.com</a:href>

This XLINK example defines a simple hyperlink to "http://example.com."


Linking Elements: XLINK introduces elements like <a>, <loc>, and <arc> to define links, locations, and
arcs in XML documents.

<?xml version="1.0"?>
<bookstore xmlns:xlink="http://www.w3.org/1999/xlink">
<book>
<title xlink:type="simple" xlink:href="http://example.com/book/1">Introduction to XML</title>
<author>John Doe</author>
</book>
<book>
<title xlink:type="simple" xlink:href="http://example.com/book/2">XML for Beginners</title>
<author>Jane Smith</author>
</book>
</bookstore>
OUTPUT:

Introduction to XML - http://example.com/book/1


XML for Beginners - http://example.com/book/2
XPATH
<?xml version="1.0"?>
<bookstore>
<book>
<title>Introduction to XML</title>
<author>John Doe</author>
<price>29.99</price>
</book>
<book>
<title>XML for Beginners</title>
<author>Jane Smith</author>
<price>19.95</price>
</book>
</bookstore>

Xpath Experssion : titles = root.xpath("/bookstore/book/title/text()")


This selects the text content of all <title> elements under <book> elements.
OUTPUT:
Introduction to XML
XML for Beginners
Xpath Experssion : expensive_books = root.xpath("/bookstore/book[price > 20]/title/text()")
This selects the text content of <title> elements under <book> elements where the <price> is greater than
20.
OUTPUT:
29.99

XQUERY

<?xml version="1.0"?>
<bookstore>
<book>
<title>Introduction to XML</title>
<author>John Doe</author>
<price>29.99</price>
</book>
<book>
<title>XML for Beginners</title>
<author>Jane Smith</author>
<price>19.95</price>
</book>
</bookstore>

XQuery : for $book in doc("books.xml")/bookstore/book where $book/price > 20


return $book/title

This XQuery example retrieves the titles of books with a price greater than 35 from an XML document
named "books.xml."

OUTPUT:
Introduction to XML
CSS (CASCADING STYLE SHEETS)
is a style sheet language used for describing the presentation of a document written in HTML or XML. It
defines how elements are to be displayed on the screen, in print, or spoken.
CSS Syntax:
selector {
property: value;
}
/* Styling paragraphs */
p{
color: blue;
font-size: 16px;
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Welcome to CSS Example</h1>
</header>
<section>
<p>This is a simple paragraph on the webpage.</p>
</section>
<button>Click me</button>
</body>
</html>
styles.css
/* Body styles */
body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
}
/* Paragraph styles */
p{
color: #333;
font-size: 1.2em;}

You might also like