Datasheet

In this book we only scratch the surface of XPath’s capabilities, but if you want to learn how to build
more complex XPath expressions, you can read more about the language and its capabilities on the W3C
web site.
JavaScript and DOM
JavaScript is another scripting language, widely known for its use in web-based applications. The
name JavaScript is something of a misnomer, as it bears only a superficial resemblance to the Java pro-
gramming language. It first appeared in Netscape’s web browser in 1995, and was incorporated into the
international standard ECMA-262 as ECMAScript. Most modern browsers incorporate an ECMAScript-
compatible scripting language the one found in Microsoft’s Internet Explorer is known as Jscript.
JavaScript is actually a registered trademark of Sun Microsystems, but is widely used as a generic refer-
ence to the scripting language used within web browsers.
Within the scripting language, web browsers typically implement the W3C standard DOM, or
document
object model
. The DOM specifies how HTML and XML documents are represented as a tree structure
within the browser. The DOM specification also specifies the programmatic interface by which the vari-
ous elements within the document tree can be manipulated.
JavaScript used to manipulate the DOM within a browser is often referred to as
dynamic HTML. Here’s a
simple example of how you might use dynamic HTML to provide interaction on a web page.
<html>
<head>
<title>Arithmetic</title>
<script type=”text/javascript”>
function showAnswer()
{
var answerNode = document.getElementById(‘answer’);
answerNode.innerHTML = “<h2>Answer</h2><p>” + (2 + 2) + “</p>”;
}
</script>
</head>
<body>
<h1>Question</h1>
<form onsubmit=”showAnswer(); return false;”>
<p>
What is the answer to the sum <code>2 + 2</code>?
</p>
<input type=”submit” value=”Show Answer” />
</form>
<div id=”answer”>
The answer will appear here
</div>
</body>
</html>
In this example, the question is placed inside a form, with a button to submit the form and show the
answer. A placeholder
<div> element is added at the end of the document and is where the answer to
the question will appear.
11
Chapter 1: Rewriting the Web
05_097748 ch01.qxp 12/14/06 5:53 PM Page 11