100% found this document useful (3 votes)
70 views

Instant Download Java XML and The JAXP 1st Edition Arthur Griffith PDF All Chapter

ebook

Uploaded by

nowrotmurali76
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
70 views

Instant Download Java XML and The JAXP 1st Edition Arthur Griffith PDF All Chapter

ebook

Uploaded by

nowrotmurali76
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 84

Full download ebook at ebookgate.

com

Java XML and the JAXP 1st Edition Arthur


Griffith

https://ebookgate.com/product/java-xml-and-the-
jaxp-1st-edition-arthur-griffith/

Download more ebook from https://ebookgate.com


More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Java and XML 3rd ed Edition Edelson

https://ebookgate.com/product/java-and-xml-3rd-ed-edition-
edelson/

Java 2EE and XML development 1st Edition Kurt A.


Gabrick

https://ebookgate.com/product/java-2ee-and-xml-development-1st-
edition-kurt-a-gabrick/

Developing Web Services with Java APIs for XML 1st


Edition Robert Hablutzel

https://ebookgate.com/product/developing-web-services-with-java-
apis-for-xml-1st-edition-robert-hablutzel/

Building Web services with Java making sense of XML


SOAP WSDL and UDDI 2nd ed Edition Graham

https://ebookgate.com/product/building-web-services-with-java-
making-sense-of-xml-soap-wsdl-and-uddi-2nd-ed-edition-graham/
Building Web Services with Java Making Sense of XML
SOAP WSDL and UDDI 2nd Edition Steve Graham

https://ebookgate.com/product/building-web-services-with-java-
making-sense-of-xml-soap-wsdl-and-uddi-2nd-edition-steve-graham/

The Vauban Fortifications of France Paddy Griffith

https://ebookgate.com/product/the-vauban-fortifications-of-
france-paddy-griffith/

Construction Management Principles and Practce 1st


Edition Alan Griffith

https://ebookgate.com/product/construction-management-principles-
and-practce-1st-edition-alan-griffith/

The Halifax Explosion and the Royal Canadian Navy 1st


Edition John Griffith Armstrong

https://ebookgate.com/product/the-halifax-explosion-and-the-
royal-canadian-navy-1st-edition-john-griffith-armstrong/

The Collected Poems of Arthur Yap 1st Edition Arthur


Yap

https://ebookgate.com/product/the-collected-poems-of-arthur-
yap-1st-edition-arthur-yap/
Java™, XML, and JAXP

Arthur Griffith

Wiley Computer Publishing

John Wiley & Sons, Inc.


NEW YORK • CHICHESTER • WEINHEIM • BRISBANE • SINGAPORE • TORONTO
3851 P- FM 1/28/02 10:19 AM Page i

Java™, XML, and JAXP


3851 P- FM 1/28/02 10:19 AM Page ii
3851 P- FM 1/28/02 10:19 AM Page iii

Java™, XML, and JAXP

Arthur Griffith

Wiley Computer Publishing

John Wiley & Sons, Inc.


NEW YORK • CHICHESTER • WEINHEIM • BRISBANE • SINGAPORE • TORONTO
3851 P- FM 1/28/02 10:19 AM Page iv

Publisher: Robert Ipsen


Editor: Cary Sullivan
Developmental Editor: Scott Amerman
Associate Managing Editor: Penny Linskey
Associate New Media Editor: Brian Snapp
Text Design & Composition: Publishers’ Design and Production Services, Inc.

Designations used by companies to distinguish their products are often claimed as


trademarks. In all instances where John Wiley & Sons, Inc., is aware of a claim, the
product names appear in initial capital or ALL CAPITAL LETTERS. Readers, however, should
contact the appropriate companies for more complete information regarding trademarks
and registration.

This book is printed on acid-free paper.

Copyright © 2002 by Arthur Griffith. All rights reserved.

Published by John Wiley & Sons, Inc.


Published simultaneously in Canada.

No part of this publication may be reproduced, stored in a retrieval system or transmitted


in any form or by any means, electronic, mechanical, photocopying, recording, scanning
or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States
Copyright Act, without either the prior written permission of the Publisher, or
authorization through payment of the appropriate per-copy fee to the Copyright
Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400,
fax (978) 750-4744. Requests to the Publisher for permission should be addressed to
the Permissions Department, John Wiley & Sons, Inc., 605 Third Avenue, New York,
NY 10158-0012, (212) 850-6011, fax (212) 850-6008, E-Mail: PERMREQ @ WILEY.COM.

This publication is designed to provide accurate and authoritative information in regard


to the subject matter covered. It is sold with the understanding that the publisher is not
engaged in professional services. If professional advice or other expert assistance is
required, the services of a competent professional person should be sought.

Library of Congress Cataloging-in-Publication Data:

ISBN: 0-471-20907-4

Printed in the United States of America.

10 9 8 7 6 5 4 3 2 1
Contents

Introduction xi

Chapter 1 Introduction to XML with JAXP 1


Java and XML 1
Java, the Language 2
XML, the Language 3
DTD 5
XSL 6
SAX 7
DOM 7
SGML 8
XHTML 9
JAXP 9
Ant 10
Summary 11

Chapter 2 XML Document Format 13


Some General Notes about Syntax 14
Names 14
Strings 15
Whitespace 15
A Fundamental XML Document 16
XML Declaration 17
XML Tags and Elements 18

v
vi Contents

Attributes 19
Comments 20
The Character Entities 20
The CDATA Section 22
DTD 22
Single File 23
Multiple Files 24
The DOCTYPE Inline Declaration 25
The DOCTYPE SYSTEM Declaration 26
The DOCTYPE PUBLIC Declaration 27
Comments 28
The ELEMENT Declaration 28
The ATTLIST Declaration 31
The ENTITY Declaration 32
Parameter Entities 34
Unparsed Entities 35
The PI Declaration 36
Conditional Inclusion with IGNORE and INCLUDE 37
Namespaces 37
A Simple Namespace 38
The Default Namespace 39
Multiple Namespaces 40
A Namespace Defined in a DTD 40
Multiple Namespaces in a DTD 41
Summary 42

Chapter 3 SAX and DOM in the JAXP 43


The SAX Parser 43
SAX 1.0 and SAX 2.0 44
The Definition of SAX 45
The DOM Parser 47
The DOM Specification 48
DOM as a Java Package 52
The Rest of JAXP 55
Summary 58

Chapter 4 SAX Document Parse and Read 59


How SAX Parsers Are Used 59
SAX Error Checking 60
MyErrorHandler 60
SAXCheck 62
SAXParserFactory 62
XMLReader 65
Contents vii

SAX Document Lister 65


MyContentHandler 67
The ContentHandler Callback Methods 70
Executing the SAX Parser 71
Summary 75

Chapter 5 SAX Document Manipulation 77


Duplicate a Document 78
Extracting XML Text 82
Formatting XML Text as HTML 87
Summary 91

Chapter 6 DOM Document Parse and Read 93


A DOM Error Checker 93
DocumentBuilderFactory 95
DocumentBuilder 96
Document 97
The Shape of the DOM Parse Tree 97
A DOM Parse Tree Lister 98
A Detailed Parse Tree Dumper 103
Listing the Contents of Parse Tree Nodes 103
DOM Parse Tree Node Types 107
Summary 112

Chapter 7 Editing the DOM Parse Tree 113


Making a Copy of a Document 113
Inserting a New Element Node 119
Locating a Node and Modifying Text 121
Deleting a Tree Node 125
Replacing a Tree Node 126
Locating Elements by Tag Name 127
Duplicating a Portion of the Tree 128
Setting an Attribute 131
Deleting an Attribute 132
Moving and Copying Attributes 133
Locating a Node by an ID 136
Editing the Text of a Node 137
Inserting a CDATASection Node 141
viii Contents

Splitting a Text Node 142


Creating a Parse Tree from Scratch 144
Moving Nodes between Documents 146
Editing by Using a Document Fragment 151
Inserting a Processing Instruction and Comment 153
Summary 154

Chapter 8 JAXP XSL Document Transformations 155


Performing a Transformation 156
Pattern Matching with XPath 160
XSL Transformations 163
Stylesheet Elements 166
xsl:apply-templates 166
xsl:value-of 169
xsl:for-each 171
xsl:include and xsl:import 173
xsl:strip-space and xsl:preserve-space 175
Creating a Web Page 175
Summary 176

Chapter 9 Ant 179


Running Ant from the Command Line 180
The Content of the Buildfile 180
Project 182
Target 182
Tasks 186
Properties 188
Directory and Filename Pattern Matching 189
Patternset 190
Fileset 191
Path and Classpath 192
Some Useful Tasks 194
available 194
chmod 195
copy 196
delete 197
echo 198
exec 199
java 201
javac 202
Contents ix

mkdir 204
move 204
Summary 205

Chapter 10 The Future 207


JAXB 207
JAXM 208
JAXR 209
JAX-RPC 209
Long-Term JavaBeans Persistence 210
Linking 210
Stylesheets 211
Other Things Are Coming 211
Summary 212

Glossary 213

Index 217
Introduction

This book is intended to provide a solid foundation in XML to a Java programmer. It


does this by describing XML and then using the API developed by Sun Microsystems
to demonstrate simple examples of the fundamentals of XML document manipulation.
You’ve heard of XML, and you have more than likely read something about it, but it all
seems a bit mysterious. My hope is that, as you read this book, from time to time you
say to yourself, “Oh. I see.”
Every attempt was made to keep the focus of the book on its primary mission of ex-
plaining XML to a Java programmer. There are very few side issues mentioned.
There is an overwhelming amount of information about XML being made available
in books, magazines, on the Internet, conferences, seminars, and even in mass mailings.
It seems that everyone is either using XML or writing software so other people can use
it. In the writing of this book, every attempt was made to distill the available informa-
tion down to its essentials so the reader would be able to get a good basis from which
to explore other areas of the subject. The intention of this book is that, after reading it,
a person can proceed into any region of XML usage and technology and have a good
understanding of the basics of what is taking place.
You will find that certain sections of the book are very tutorial-like, while other
places are obviously intended for reference. In particular, Chapter 2 is almost com-
pletely reference information on the syntax for XML tags and the DTD used to add re-
strictions to the syntax. The rest of the reference material is found throughout the book
in places where it is relevant.
One chapter discusses what could be considered a side issue. The chapter on Ant is
about a utility that can be used to manage software development. But is not far off
topic. Ant is an XML application that is written in Java and can be extended by your
adding classes that process new instructions, that are defined as XML elements. And
Sun provides Ant files with its JAXP distribution. It is the only large XML application
discussed in the book.

xi
xii Introduction

Prerequisites
This is a beginner’s book for XML, but it is not a beginner’s book for general comput-
ing or programming. The following things are required of the reader:

1. The fundamentals of Java must be understood. This includes the concepts of in-
heritance, interfaces, static methods, properties, instantiation, and polymorphism.
If you have sucessfully written a few classes in Java, and you have a good refer-
ence book, you have everything you need.
2. There should be some familiarity with the basic structure of HTML.
3. The reader must have Internet access and should have some rudimentary un-
derstanding of URLs and the process of transferring files from one location to
another.

The following knowledge would be helpful but is not absolutely necessary:

1. Knowledge of the operation of lexical scanners and parsers.


2. An understanding of the basic structure of the ASCII and Unicode character sets.

How to Read This Book


To cover the entire subject, the book can be read straight through beginning with Chap-
ter 1. And that is what I would suggest for someone entirely unfamiliar with XML and
wanting to know about all of it. The examples are small and to the point—each one is
designed to demonstrate just one idea—so it should take you quickly from one point to
the next.
If you elect to read only portions of the book to extract information about certain as-
pects of XML, I would suggest that you at least skim through Chapters 1 and 2. These
two chapters will provide you with a high-level overview of the Java software and a
concise look at the structure of XML.
If you want a simple XML document reader, Chapters 3, 4, and 5 explain the SAX
parser, which will read the document while checking its syntax and feed the document
to your application in the form of a stream of tokens.
If you want a complete precedence-driven parser that gives you random access to
the input document, Chapters 3, 6, and 7 describe the DOM parser.
If you are wanting to know how to process XML documents using XSL stylesheets,
look at Chapter 8. Because XSL uses the same tree structure produced by the DOM
parser, you will also need to be familiar with the information presented in Chapters 4
and 5.
If you are going to be starting a Java project you should look into Chapter 9 before
you start. The Ant utility can be used to manage, cleanly and simply, a Java project of
any size. I use it myself and have had great success with it.
Java™, XML, and JAXP
3851 P- FM 1/28/02 10:19 AM Page xiv
3851 P-01 1/28/02 10:32 AM Page 1

CHAPTER

1
Introduction to
XML with JAXP

This chapter is an overview of some of the basic things you will need to know before
you can understand the processing of XML documents using Java’s Java API for XML
Processing (JAXP). Although the Java application programming interface (API) is rather
straightforward, you will need to understand how XML is constructed before you can
clearly understand the sort of things that can be done with the API. The fundamental
concepts described in this chapter include the fact that, like HTML, the XML language
is derived from SGML. This kinship between XML and HTML has brought about the ex-
istence of a hybrid known as XHTML. There are two completely distinct parsers, named
DOM and SAX, that can be used to read the contents of an XML document.

Java and XML


Java was designed to make it possible to write completely portable programs. XML
was designed to make it possible to create completely portable data. In an ideal situa-
tion, using the two together will make for a completely portable software package that
can communicate its data with any other completely portable software package. Noth-
ing is absolutely perfect, but these two, used together, come about as close as anything
that has been developed so far in terms of the ability to write a program that runs on
any type of computer and can swap data with any other type of computer.

1
3851 P-01 1/28/02 10:32 AM Page 2

2 Chapter 1

The JAXP package is a set of Java classes that implements XML document parsers,
supplies methods that can be used to manipulate the parsed data, and has special
transformation processors to automate the conversion of data from XML to another
form. For example, the other form can be a database record layout ready for storage, an
HTML Web page ready for display, or simply a textual layout ready for printing.
One of the outstanding features of XML is its fundamental simplicity. Once you un-
derstand how tags are used to create elements, it is easy to manually read and write
XML documents. With this basic XML understanding, and with knowledge of the Java
language, it is a straightforward process to understand the relationship between XML
and the Java API for manipulating XML. There are only a few classes in this API, and
it is only a matter of creating the appropriate set of objects, and they will supply the
methods you can call to manipulate the contents of an XML document. With these basic
concepts understood, and with the simplicity of the constructs involved, you can de-
sign and write programs while concentrating mostly on the problem you are trying to
solve, not on the mechanics of getting it done.

Java, the Language


Following are some characteristics of Java that make it ideal for use as a language to
manipulate XML documents:
■ The JAXP is now a part of standard Java. It contains all of the classes and inter-
faces that you need for parsing and processing an XML document. It also con-
tains methods that can be used to automate the transformation process of
converting an XML document into an entirely different form.
■ The fundamental Java stream IO can be used for input of XML documents and
output of the results of processing. This means that your application is able to
process files stored remotely on the Internet just as easily as the ones on the local
disk. Once a stream has been established to a file, the rest of the application can
use streaming input and output without having to know anything about the lo-
cation at the other end of the stream. You can write your application just once
and know that it will work no matter how the data needs to be fed to or extracted
from it.
■ The majority of installed Web servers are capable of running Java applications
to dynamically generate Web pages. This means that, using the JAXP, the set of
Java classes that provide the methods to be used to manage XML documents, it
becomes a very simple matter to transform data from an XML format to HTML
format as a response to a request made from a remote Web browser. All of the
software you need, from receiving the request through formatting the data to
transmitting the response, is ready and waiting. About all that is left to do is de-
cide how you want the Web page to appear and then write the Java code to lay
it out.
■ Portability applies to anything written in Java. Using Java and its built-in JAXP
allows you to run the application on any computer that has a Java Virtual Ma-
3851 P-01 1/28/02 10:32 AM Page 3

Introduction to XML with JAXP 3

chine installed. And, because XML is also portable, the result is an almost uni-
versally portable system and can be used in exactly the same way on any com-
puter.

To fully understand the concepts discussed in the following paragraphs and chap-
ters, you should be familiar with Java, or familiarize yourself with the Java program-
ming language using Java tutorials. To understand how these classes do their jobs, you
will only need to understand Java classes, objects, interfaces, and methods. There is
nothing more complicated than a static method returning an object that implements an
interface; if you understand these fundamentals, you will have no problem with any-
thing in this book.

XML, the Language


XML stands for Extensible Markup Language. These three words are actually a very ac-
curate description. It is a nonprocedural programming language, which means that
things written in the language are not so much commands as they are descriptions of a
condition or state. Like almost all programming languages, XML is written as human-
readable text, in such a form that humans as well as programs can read and understand
the instructions.
The XML language is used to mark up a document so that the reader (usually a pro-
gram) can identify each piece of the document and determine its characteristics by ex-
amining the tags it contains. A tag can be named anything you would like, but it only
has meaning if the program reading the document already knows the tag name. XML
is also extensible because you can invent as many markup tags as you need as you go
along; all you need to do is make sure the reader of the document knows the meanings
of your tags. In fact, there are no markup tags defined as part of XML. The creator of
an XML document invents whatever tags are necessary for a full description of the doc-
ument being marked up.
There is a common misconception that the purpose of XML is to format and display
data. That is not what it is for. Its purpose is to store data in a form that can be easily
read and analyzed. It is quite common to use XML to store data and use the descriptive
XML tags to specify how it should be displayed, but this not an inherent part of XML.
It is also very common to write applications that convert XML data into HTML for dis-
play. And, because XML and HTML are so similar in their basic syntax, it is possible to
use the tag names defined for HTML in an XML document and then use a Web browser
to display it as if it were HTML. A special name for this type of XML document is
XHTML, but it is just a special case of XML.
A file, or other entity, containing XML-formatted data is referred to as a document.
This term carries a broad interpretation because XML is used to format many different
kinds of information, some of which is never intended for human use (such as data
being transferred from one database to another). The following examples show how
tags can be used to mark up documents. An XML document can be for any purpose
and can take any form it needs to fit that purpose, but generally speaking, there are two
categories of XML documents. An XML document can be storage for text that is in-
3851 P-01 1/28/02 10:32 AM Page 4

4 Chapter 1

tended to be formatted and presented in a readable format. Or it can be a convenient


form for packaging data records for transmission from one place to another, or simply
for storage, in a portable format. The following is an example of text that can be for-
matted for display:

<paragraph>
The purpose of this type of XML document is to use
<italic>tags</italic> in such a way that the software that
reads the document will be able to <underline>organize</underline>
and <underline>format</underline> the text in such a way that
it is more presentable and easier to read.
</paragraph>

This form of XML looks a lot like HTML. In fact, this form of XML and HTML both
serve exactly the same purpose: to allow the software reading the document to extract
things from it and also to use the tags as formatting instructions to create a display
from the extracted text.
The same basic form can be used to package data, as in the following example:

<person>
<name>Karan Dirsham</name>
<street>8080 Holly Lane</street>
<city>Anchor Point</city>
<state>Alaska</state>
<zip>99603</zip>
</person>

This second form is more like a collection of fields that go to make up a data record, and
used this way, it can be a very convenient method for storing data and transmitting in-
formation among otherwise incompatible systems. All that is necessary for successful
data reception of transmitted data is for the recipient to understand the meanings of the
tags and be able to extract the data from them. Of course, by using the appropriate ap-
plication to read and process the data, any XML document can be easily formatted for
display. The process of extraction and formatting XML data is the primary subject of
this book.
Attributes can be used to specify options that further refine the meaning of the tags
to the process reading the document. These attributes can be used both for data defin-
ition and for formatting. For example, the following code has attributes:

<person font="Courier">
<name type="first" enhance="bold">Janie</name>
<name type="last" enhance="underline">Rorick</name>
</person>

Any program reading this document can apply its own interpretation to the mean-
ings of the tags and the options. No formatting information is included in an XML doc-
ument. All formatting is left entirely to the process reading and interpreting the XML
document. One program could read a document containing this example and take the
3851 P-01 1/28/02 10:32 AM Page 5

Introduction to XML with JAXP 5

bold option to mean a different font, another could take it to mean a larger font, and an-
other could use it as an instruction to underline the text or display it in a different color.
Or the bold option could be ignored altogether. The only thing XML knows about the
attribute is the syntax required to include it with a tag.
If you have worked with HTML, you can see the similarities in the syntax of HTML
and XML. They are similar enough that it is possible to write an XML document and
use only tag names known to a particular Web browser and then have that Web
browser read the document and impose its interpretations on the tags and options and
result in a displayed page. A displayable XML document is written often enough that
a document of this type has a special name; it is called XHTML. There is more infor-
mation about XHTML later in this chapter.
XML is a nonprocedural computer language, as opposed to a procedural language such
as Java. A procedural language is one that consists of lists of instruction that are ex-
pected to be obeyed one by one, usually in order from top to bottom. A nonprocedural
language is one that expects all of its instructions to be executed as if they were all
being executed simultaneously and, if necessary, to react to one another to create an
overall state or set of states. An example of nonprocedural processing is a spreadsheet
in which all the cells in the sheet that contain equations have their values calculated at
once, creating a static state of constant values displayed in the cells. This same sort of
thing happens in a Web browser where the HTML tags define the state (layout, colors,
text, pictures, fonts, and so on) that determines the appearance of a Web page.

DTD
DTD stands for Document Type Definition. Although DTD is normally treated sepa-
rately from XML tags, has a different syntax, and serves a different purpose, it is very
much a part of the XML language. The DTD section of an XML document is used to de-
fine the names and syntax of the elements that can be used in the document. There are
several steps involved in the creation and application of a DTD definition, and Chap-
ter 2 contains explanations of those steps along with a number of examples. Its source
can be included inline inside an XML document, or it can be stored in a separate docu-
ment from the XML text and tags. Because its purpose is to specify the correct format
of a marked up document, DTD is most useful if it is made available to several docu-
ments and is most often stored in a file separate from any XML document, which en-
ables it to be accessed from any number of XML documents. For the sake of simplicity,
however, most of the examples in this book have a simple DTD included as part of the
XML document.
DTD enables you to further refine the syntactical requirements of a set of XML
markup rules. In a DTD you can specify the allowed and disallowed content of each tag
that is to appear in an XML document. That takes at least a third of Chapter 2. DTD has
its limitations, but there are many different things that can be done by using it. You can
specify which elements are allowed to appear inside other elements as well as which el-
ements are required and where they are required. You can specify which attributes are
valid for each tag and even specify the set of possible values for each one. You can
3851 P-01 1/28/02 10:32 AM Page 6

6 Chapter 1

create macro-like objects (called entities) that are expanded into text as the XML docu-
ment is parsed. All of this is explored in Chapter 2.
An XML document that conforms to the fundamental syntax of markup tags is
called well-formed. To be a well-formed document, all elements must have matching
opening and closing tags, and the tags must be nested properly. For example, the ex-
pression <p><b>text</b></p> is well-formed because the opening tags, <p><b>,
have closing tags, </b></p>, and they are nested properly. To be well-formed every
closing tag must be a match with the most recent tag that is still open. In short, all tags
must be closed in the exact reverse order in which they were opened. The expressions
<p><b>text</b> and <p><b>text</p></b> are not well-formed.
An XML document that conforms to the rules of its DTD is referred to as a valid doc-
ument. For a document to be successfully tested as being valid, it must also be well-
formed. Some parsers can check the document against the DTD definitions and throw
an exception if the document is not valid.
Use of DTDs is very important to the portability of XML. If a DTD is well written
(that is, if all the tags are defined properly), a process can be written that will be able to
read and interpret any XML data from any document that conforms to the rules of the
DTD.
A single XML document can use more than one DTD. However, this multiple DTD
use can result in a naming collision. If two or more DTDs define a tag by the same
name, they will more than likely define that tag as having different characteristics. For
example, one could be defined as requiring a font attribute, whereas the other has no
such attribute. This problem is solved by using device known as a namespace. An ele-
ment specified as being from one namespace is distinct from one of the same name
from another namespace. For example, if a pair of DTDs both include a definition for
an element with the tag name selectable, one DTD could be declared in the name-
space max and the other in the namespace scrim; then there would be the two distinct
tag names max:selectable and scrim:selectable available for use in the docu-
ment. Examples using namespaces are explained in Chapter 2.

XSL
XSL stands for XML Stylesheet Language. It is used as a set of instructions for the
translation of the content of an XML document into another form—usually a presenta-
tion form intended to be displayed to a human. An XSL program is actually, in itself, a
document that adheres to the syntax of XML. It contains a set of detailed instructions
for extracting data from another XML document and converting it to a new format. Per-
forming such transformation is the subject of Chapter 8.
The process of using XSL to change the format of the data is known as transformation.
Transformation methods are built into the JAXP that can be used to perform any data
format translation you define in an XSL document. These transformations can be pro-
grammed directly into Java instead of using XSL, but XSL simplifies things by taking
care of some of the underlying mechanics, such as walking through the memory-
resident parse tree to examine the source document. It also supplies you with some
3851 P-01 1/28/02 10:32 AM Page 7

Introduction to XML with JAXP 7

built-in methods for doing commonly performed tasks such as configuring the parser
and handling error conditions.
XSL performs a function—supplying human-readable data—that is every bit as im-
portant as XML itself. With the single exception of robotics, all the software in the
world is ultimately used to display data to humans. Nothing is ever stored in a data-
base without the expectation that it will be extracted and presented in some human-
readable format. In fact, presenting readable data is the entire purpose of the Internet.
Operating systems and computer language compilers only exist to support and create
other programs that, in turn, directly or indirectly present data in a form that can be un-
derstood by humans.

SAX
SAX stands for Simple API for XML. It is a collection of Java methods that can be used
to read an XML document and parse it in such a way that each of the individual pieces
of the input are supplied to your program. It is a very rudimentary form of parsing that
is not much more than a lexical scan: It reads the input, determines the type of things
it encounters (it recognizes the format of the nested tags and separates out the text that
is the data portion of the document), and supplies them to your program in the same
order in which they appear in the document.
The form of the data coming from a SAX parser can be very useful for streaming op-
erations such as a direct translation of tags or text into another form, with no changes
in order. If your application needs to switch things around, however, it will be neces-
sary for it to keep copies of the data so it can be reorganized. In many cases, it would
be easier to parse using the DOM parser. The SAX parser has the advantage of being
fast and small because it doesn’t hold anything in memory once it has moved on to the
next input item in the input document.
There are two versions of SAX. The original version is SAX 1.0 (also called SAX1).
The current version is SAX 2.0 (also called SAX2). SAX2 is an extension of the defini-
tions of SAX 1.0 to include things such as the ability to specify names using name-
spaces. Both SAX1 and SAX2 are a part of JAXP. Because SAX1 is still a part of JAXP,
programs based on it will work , but much of it has been deprecated in the API to pro-
mote use of SAX2 in all newly written programs. Only SAX2 is discussed in the fol-
lowing chapters because it does everything SAX1 does and more.

DOM
DOM stands for Document Object Model. It is a collection of Java methods that enable
your program to parse an input document into a memory-resident tree of nodes that
maintains the relationships found in the original input document. There are also meth-
ods that enable your application to walk freely about the tree and extract the informa-
tion stored there.
3851 P-01 1/28/02 10:32 AM Page 8

8 Chapter 1

The internal form of the data tree resulting from a DOM parse is quite convenient if
you are going to be accessing document content out of order. That is, if your program
needs to rearrange the incoming data for its output, or if it needs to move around the
document and select data in random-access order, you should find that the DOM doc-
ument tree will provide what you need for doing this. You can search for things in the
tree and pull out what you need without regard to where it appeared in the input doc-
ument. One disadvantage of DOM is that a large document will take up a lot of space
because the entire document is held in memory. With modern operating systems, how-
ever, the document would need to be extremely large before it would adversely affect
anything. DOM also has the disadvantage of being more complicated to use than SAX.
Because DOM can randomly access the stored data, the API for it is necessarily more
complex. Although DOM is more complicated to use than SAX, it can be used to do
much more. For more details about how DOM works, see Chapters 3, 6, and 7.
Internally in the JAXP, the DOM parser actually uses SAX as its lexical scanner. That
is, a SAX parser is used to read the document and break it down into a stream of its
components, and the DOM software takes this token stream and constructs a tree
from it. This is why it is best to have an understanding of SAX before trying to get a
clear idea of how JAXP DOM works. Although you may never use SAX directly, it’s a
good idea to know how it works and how the incoming document is broken down. At
the very least, you will need to be familiar with the meaning of its error messages and
how to process them in your application, which means you will need to know how
SAX works. For more details, see Chapters 3, 4, and 5

SGML
SGML stands for Standard Generalized Markup Language. This is the parent markup
language of XML and HTML, which were both derived as special-purpose subsets of
SGML. Included in the 500-page SGML specification document is a definition of the
system for organizing and tagging elements in a document. It became a standard with
the International Organization of Standards (ISO) in 1986, but the specification had ac-
tually been in use some time before that. It was designed to manage large documents
so that they could be frequently changed and also printed. It is a large language defin-
ition and too difficult to actually implement, which has resulted in the subsets XML
and HTML.
XML works well being a subset of SGML because the complexity of SGML isn’t nec-
essary to do all of the tagging and transforming that needs to be done. Being a practi-
cal subset makes it much easier to write a parser for XML. Because of the reduction in
complexity of the language, XML documents are smaller and easier to create than
SGML documents would be. For example, where SGML always requires the presence
of a DTD, in XML the DTD is largely optional. If you are going to validate the correct-
ness of an XML document, the DTD is necessary, but otherwise it can be omitted.
XML is a bit closer to being like SGML than is HTML. For one thing, HTML is filled
with ambiguities because it allows things like an opening tag that has no closing tag to
match it. This prevents any attempts to standardize HTML because a parser cannot
3851 P-01 1/28/02 10:32 AM Page 9

Introduction to XML with JAXP 9

predict what it will find. And many HTML extensions and modifications apply in one
place but do not apply in another. Although XML is extensible—you can add all the tag
types you wish—it is very strict in the way it allows you to do it. Like SGML, the for-
matting of XML can be controlled by XSL documents used for transformations.

XHTML
XHTML stands for Extensible Hypertext Markup Language. An XHTML document is
a hybrid of XML and HTML in such a way that it is syntactically correct for both of
them. That is, although an XHTML document can be displayed by a Web browser, it
can also be parsed into its component parts by a SAX or DOM parser. Both XML and
HTML are subsets of SGML, so the only problem in combining the two into XHTML
was in dealing with the places where HTML had departed from the standard format.
Most obvious are the many opening tags in HTML that do not have closing tags to
match them and the fact that tag nesting is not required.
XHTML was conceived so that, once Web browsers were capable of dealing with the
strict and standard forms required for XML, a more standardized form of Web page
could evolve. With XML it is relatively easy to introduce new forms by defining addi-
tional elements and attributes, and because this same technique is part of XHTML, it
will allow the smooth integration of new features with the existing ones. This capabil-
ity is particularly attractive because alternate ways of accessing the Internet are con-
stantly being developed. The presence of a standard, parsable Web page will allow
easier modification to the display format for new demands, such as the special re-
quirements of hand-held computers.
There is a fundamental difference between XML and HTML. XML is an SGML,
while HTML is an application of SGML. That is, SGML does not have any tag names de-
fined and neither does XML. For both XML and SGML, a DTD must be used to define
and provide meanings for element names. On the other hand, HTML has a set of ele-
ment names already defined. The element names of HTML are the ones that have a
meaning to the Web browser attempting to format the page. This fundamental differ-
ence between XML and HTML can be overcome by the creation of a DTD that defines
the syntax for all the elements that are used in HTML. With such a DTD in place, an
XML document that adheres to the DTD’s definitions will also be an HTML document,
and thus it can be displayed using a Web browser.

JAXP
JAXP stands for Java API for XML Processing. It is a set of Java classes and interfaces
specifically designed to be used in a program to make it capable of reading, manipu-
lating, and writing XML-formatted data.
It includes complete parsers for SAX1 and SAX2 and the two types of DOM: DOM
Level 1 and DOM Level 2. Most of this book explores the use of parsers in extracting
3851 P-01 1/28/02 10:32 AM Page 10

10 Chapter 1

data from an XML document. More information on both of these parsers is the subject
of Chapter 3. There are examples of using the SAX parsers in Chapters 4 and 5 and of
the DOM parsers in Chapters 6 and 7. All of the parsers check whether a document is
well-formed, and the parsers can be used in validating or nonvalidating mode, as de-
scribed in the DTD section earlier in this chapter. There is also an extensive API that can
be used to access the data resulting from any of these parsers. And although SAX1 and
DOM Level 1 are both present and working, the API for them is deprecated. Anything
you need to do can be accomplished with just the SAX2 and DOM Level 2 API.
The simplest way to get a copy of JAXP is to download and install the latest copy of
Java from Sun at http://java.sun.com. Beginning with Java version 1.4, the JAXP API is
included as part of Java 2 Standard Edition. It is also a part of the Java 1.3 Enterprise
Edition. If you want to use JAXP with a prior version of Java, you can get a copy of it
from the Web site http://java.sun.com/xml. You can use JAXP version 1.1 with the
Java Software Development Kit ( SDK ) version 1.1.8 or newer.
If, for some reason, you are staying with an older version of Java and downloading
JAXP as a separate API, you will need to download the documentation separately.
This documentation is in the form of a set of HTML pages generated from the source
code by the standard javadoc utility. It is in the same format as the documentation for
the rest of Java. There are two ways to install the standalone JAXP: You can include its
jar files in the same directories as your Java installation, or you can install them in their
own directories. If you do not elect to include them with Java, you will need to specify
the classpath settings when either compiling or running a JAXP application.

Ant
Ant is a tool used to compile Java classes. It isn’t limited to Java; it can be used for your
entire software development project. It performs the same job as the traditional make
utility by compiling only the programs that need to be compiled, but it has some spe-
cial features that cause it to work very will with Java. For one thing, it understands the
Java package organization and can use it when checking dependencies. It is an XML
application and, as such, uses an XML file as its input control file (much like the make
utility uses a makefile) to determine which modules to compile. The Java classes of
Ant are available in source code form, so you can, by extending the existing classes, add
any new commands and processing that you would like.
When compiling Java, Ant compares the timestamp of the source files to timestamp
of the class files to determine which Java source files need to be compiled. Also, Ant
knows about the relationship between Java directory trees and packages, so it is capa-
ble of descending your source tree properly to create classes within several packages.
For more information about Ant, with examples, see Chapter 9. The Web site for Ant
is http://jakarta.apache.org/ant/.
3851 P-01 1/28/02 10:32 AM Page 11

Introduction to XML with JAXP 11

Summary
This chapter is an overview of the basics. You should now have some idea of what
JAXP is designed to do and a rough idea of how it does it. Using JAXP, a Java program
is capable of reading an XML document and analyzing its various parts for meaning or
formatting. There is more than one way to read a document: You can do it in a se-
quential manner with a SAX parser or browse about the document randomly by using
a DOM parser.
The next chapter takes a detailed look at the syntax of an XML document. As you
will see, its tags and content are straightforward and easy to read and write. The com-
plexities of the syntax are all contained in the DTD portion. Chapter 2 describes the
syntax and is designed to make it easy for you to use as a reference later.
3851 P-01 1/28/02 10:32 AM Page 12
3851 P-02 1/28/02 10:31 AM Page 13

CHAPTER

XML Document Format

This chapter examines the syntactical format of an XML document. At the top of each
document is a heading making the declaration that it is an XML document. Next there
is an optional Document Type Definition (DTD) that defines some specific syntax rules
that must be followed for the remainder of the document. Finally, the body of the doc-
ument itself consists of text and the tags that are used to mark it up.
The body of an XML document contains text marked with tags that describe the text.
The original intent of XML was to ensure that humans could easily read and write XML
documents, so all XML documents contain only text. When binary data—such as an
image or an audio file—must be included, the binary file is stored separately, and the
XML document contains a reference to that file.
All of the text of an XML document is included between pairs of tags. If you are fa-
miliar with HTML, you know how this works (although XML is much more strict
about it than HTML). A tag can be identified by its name, and every opening tag has a
closing tag with the text itself sandwiched between them. Unlike HTML, when writing
an XML document, you can create your own tag names. In creating your own tag
names, however, it is essential that you use tags known to the process that will receive
and read the XML document. The program must recognize what the tags are and what
they mean. Most of this book concerns itself with processes that read XML documents
and process tag data.
Very much a child of the Internet, XML makes it easy to complete the text of a doc-
ument by including links to data and text files stored in remote locations. In fact, the

13
3851 P-02 1/28/02 10:31 AM Page 14

14 Chapter 2

XML language itself has the ability to require the presence of data resources in a remote
location. These resources can be simply data, or they can be schema information used
to validate the correctness of the tags and the general format of a document. This means
that the parser—the program that reads an XML document—must be able to read in-
formation from another host on the Internet.
There are really two syntaxes built into XML. One is the tag-based form used for lay-
ing out the document itself, and the other is the DTD syntax that can be used by the
parser to validate the form and content of the text and attributes of tags throughout the
document. In other words, the tags define the content of a document, and the DTD can
be used by the parser as a sort of XML watchdog by making sure that the tags are used
correctly. As you will see in this chapter, the syntax is quite different and the two are
in separate locations in the document. The DTD is optional in that it carries no data; the
exact same XML document can be written with or without the DTD.

Some General Notes about Syntax


The syntax of XML allows you to create a document in any format you would like, and
at the same time, it allows you to use tagging to restrict or define the content any way
you would like. To achieve this, the body of an XML document is free-form text inter-
mixed with tags that specify the context of the text. These tags are known as markup and
are designed to be read and processed by an XML parser. The tags have a distinct for-
mat that distinguishes them from the textual content of the document.

Names
Tag names are made up from specific characters. The first character of a name must be
one of the following:

A-Z a-z _ :

Following the first character of the name, the rest of the characters must each be one of
the following:

A-Z a-z . - _ :

Upper- and lowercase characters are distinct. These are all characters from the ASCII
character set. If you are using Unicode, you can also use the alphabetic characters from
any other language as name starters and as internal name characters. As you can see,
digits are not allowed in a name, and a name cannot begin with a period or a hyphen
(minus sign). A name can be of any length.
There is a concept in XML that deals with grouping names into namespaces to sim-
plify the organization of complicated documents. There are more details on this later in
the chapter. If a name contains a colon, it can actually be two names; the part before the
colon is the namespace in which the name is found, and the part after the colon is the
actual name. Because the specification of namespace came along after the specification
3851 P-02 1/28/02 10:31 AM Page 15

XML Document Format 15

for XML, and is still in a separate document, the use of colons is valid in any name.
However, namespace uses this fact to add some scoping to names.
Names beginning with the three-letter sequence XML (upper- or lowercase in any
combination) are all reserved for future use. You may be able to use a name starting
with these three letters and find that it is not currently reserved, but it may become re-
served in some future version of XML.

Strings
Throughout XML you will find quoted strings. The examples in this book almost ex-
clusively use double quotes to create these strings, but it doesn’t have to be that way.
It’s just a matter of style and personal preference. Anywhere you see a pair of double
quotes defining a string, a pair of single quotes (apostrophes) could have been used.
That is:

"This is a string"

is exactly the same as:

'This is a string'

The ability to select the type of quotes makes it convenient for including either single
or double quotes as a character inside a string. For example, if you need to include a sin-
gle quote character inside a string, simply create the string using double quotes, like this:

"This won't cause a problem"

The same is true for the opposite situation; you can include double quotes in a string
created using single quotes. For another way to insert quotes, and other special char-
acters, see the discussion on entities later in this chapter.

Whitespace
The whitespace characters are listed Table 2.1. All other valid characters, including
ones like backspace and form feed, are assumed to be part of the XML document.
The handling of whitespace is largely up to the application program reading the doc-
ument, but there are some actions that will be taken automatically by the parser unless

Table 2.1 The Whitespace Characters

NAME HEXADECIMAL VALUE

space 0x20
tab 0x09
line feed 0x0A
carriage return 0x0D
3851 P-02 1/28/02 10:31 AM Page 16

16 Chapter 2

you specify otherwise. For example, it’s normal for the parser to strip out some of the
whitespace characters to allow the document to be formatted in a readable fashion. If
you’ve worked with HTML, you’re familiar with this type of action. For example, it’s cus-
tomary to indent the tags to help indicate which ones are nested inside others, as follows:

<outer>
<inner>
<bold>Text of the inner tag.</bold>
</inner>
<outer>

In this example it is perfectly all right for the parser to strip out all of the whitespace be-
tween the tags. However, if you have text that should retain all of its whitespace char-
acters exactly as written, you can command the parser to not make any changes by
using the xml:space attribute as follows:

<poem xml:space="preserve">
Algy met a bear.
The bear was bulgy.
The bulge was Algy.
</poem>

If the spacing is allowed to default, however, there is no standard way that white-
space is to be handled by the parser, and your application would have no way of know-
ing how the text was originally formatted. An example is:

<outer>
<inner>
Text of the inner tag.
</inner>
<outer>

This example demonstrates a situation where the newline character at the end of the
text and the blanks in front of it could each be reduced to a single space (as is done in
HTML). The problem is that different parsers may handle this type of situation in dif-
ferent ways; some will leave them in and others will strip them out.
Bottom line: Use xml:space="preserve" in every case where whitespace reten-
tion is important. Otherwise, assume that any sequence of two or more whitespace
characters will be reduced to a single space. But remember that the default action will
vary from one parser to the next; there are even parsers that ignore any settings you
may have for xml:space.

A Fundamental XML Document


A simple XML document is quite readable by a human because it is written in plain text
as opposed to binary code. If you’re familiar with HTML, you’ll have no problem rec-
3851 P-02 1/28/02 10:31 AM Page 17

XML Document Format 17

ognizing the form of the following simple document. The data contained in the docu-
ment shown in Listing 2.1, which is the text outside of the tags, lists the names and con-
tact information of a couple of people.
The first line of Listing 2.1 identifies it as an XML document. This is not strictly re-
quired, but it is a very good idea to include it at the top of every document so the type
and version of your document can be verified. This type of instruction is known as a
processing instruction (PI) because its purpose is to pass instructions to the process that
will be reading the document.
The data contained in the document is the text, and each piece of text is enclosed be-
tween a pair of tags—one opening and one closing tag—and the tags specify the mean-
ing of the text. For example, the name of each person is preceded by a <name> tag and
is terminated by a </name> tag. These tags give the data in an XML document identity
Notice how the tag pairs are nested one inside the other. The outermost tag pair,
which is <folks> at the top and </folks> at the bottom, is called the root tag. The
outermost pair of tags in every XML document are the root tags. All of the text of an
XML document is enclosed by the root tag pair, and, inside the pair of root tags, there
are normally other tag pairs that define pieces of the text further.

XML Declaration
Every XML document should have, as its first line, an XML declaration that specifies
the version number. The current, and only, version of XML is 1.0, so a minimum dec-
laration line looks like the following:

<?xml version="1.0"?>

This declaration is not an actual XML requirement, but it’s a very good idea. It’s im-
portant to include the version number because it’s possible that there will be future ver-
sions of XML that contain features not compatible with version 1.0, and the version
number may be crucial to how future parsers deal with XML documents.

<?xml version="1.0"?>
<folks>
<person>
<name>Bertha D. Blues</name>
<phone>907 555-8901</phone>
<email>[email protected]</email>
</person>
<person>
<name>Fred Drew</name>
<phone>907 555-9921</phone>
<email>[email protected]</email>
</person>
</folks>

Listing 2.1 A Simple XML Document


3851 P-02 1/28/02 10:31 AM Page 18

18 Chapter 2

Other information is often included with the declaration. The following example
specifies that the text is Unicode in a compressed form (in other words, it’s an ASCII file
that allows for expanded 16-bit Unicode characters). Also, this declaration specifies that
the XML document doesn’t make references to external documents, so it can be read
and used as completely self-contained data.

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

The encoding value is the name of the character set used to write the XML docu-
ment. For the encoding value to have any meaning, the name must be recognized by
the program reading and processing the document. Because Java, by default, inputs
text as UTF-8, there’s no need to specify the encoding unless you’re going to do some-
thing unusual. If you know the document will be limited to 7-bit ASCII, you can de-
clare the encoding to be "US-ASCII". Also, a declaration of "UTF-8" works for
standard 7-bit ASCII because UTF-8 includes all of the ASCII characters (values from
0x00 through 0x7F), but it’ll also allow for the recognition of properly encoded Unicode
characters. Java easily reads and writes this format without you having to specify any-
thing else. If the text uses what is commonly called the extended ASCII characters (val-
ues from 0x10 through 0xFF), the encoding should be one of the names "ISO-8859-1"
through "ISO-8859-9" and cannot be "US-ASCII" or "UTF-8".
There are many other encodings possible. If you’re going to need some special
encoding, it would be best to use one of the Internet Assigned Numbers Authority
(IANA) character-set names. For the official and exhaustive list take a look at
http://www.iana.org/assignments/character-sets.
The standalone attribute specifies whether external documents are referenced
from inside this XML document. If standalone is "yes", it specifies that there are no
external documents referenced, and the parser, knowing it only needs to work with this
one file, can execute in a way that makes the processing more efficient. If it is "no", the
document may—but doesn’t necessarily have to—refer to an external document.
The declaration is in the form of a PI that begins with the character pair <? and is
terminated by ?>. This XML declaration is a very special PI that appears at the top of
every document. There’s more information on the purpose and form of PIs later in this
chapter.

XML Tags and Elements


An XML tag begins with a less-than character, ends with a greater-than character, and
contains an identifying name. Each XML tag has an identifying name that begins with
a letter or an underscore character and can contain letters, digits, periods, hyphens, and
underscores. You can also include a colon as part of the name, but that is used for spec-
ifying namespaces, which are described later in this chapter.
There are some reserved names that you can’t use for any other purpose. Any name
that begins with xml (or XML, or any other upper- and lowercase combination) should
not be used. Names that begin with these three letters are reserved for system use. An
example of this is the name xmlns used for namespaces. There is a more complete de-
finition of name formats earlier in this chapter.
3851 P-02 1/28/02 10:31 AM Page 19

XML Document Format 19

All tags have both an opening and a closing. In the following example the opening
tag is <paragraph> and the closing tag is </paragraph>. The opening and closing
tags have the same name. An opening tag has no slash character, whereas the closing
tag always has one:

<paragraph>The running board fell off!</paragraph>

A tag pair, along with any text or other tag pairs it contains, is a single unit known
as an element. An element may contain any amount of text and any number of elements.
An XML document is made up of a collection of elements nested one inside the other.
The outermost element is the root element.

NOTE XML names are case sensitive. The tags <subtitle>, <Subtitle>,
<SubTitle>, and <SUBTITLE> are all different tags. Likewise, keywords of the
XML language are case sensitive; although DOCTYPE and ELEMENT are both
keywords in XML, Doctype and element are not.

An element isn’t required to contain anything between its opening and closing tags.
The following is an example of an empty element:

<paragraph></paragraph>

Empty elements occur often enough that there’s a special shorthand notation for them.
Following is an example of the shorthand notation for an empty element:

<paragraph/>

In this example, there’s only one tag, but because the trailing slash is included, it acts
as both the opening and closing tag of an empty element.

Attributes
It’s possible to specify one or more attributes as part of an opening tag. The attributes
normally modify or amplify the meaning of the tag. For example, the following form
could be used to specify the font to be applied to the text of a paragraph:

<paragraph font="Times">The running board fell off!</paragraph>

All attributes take this same form. There is an attribute name (font in this example), fol-
lowed by an equal sign and a quoted string. The quoted string is the value of the named
attribute. It is possible to include more than one attribute with a tag. An example is:

<section type="sidebar" font="Courier" style="bold">Text</section>

As with all quoted strings in XML, you can use double quotes or single quotes to
specify the value. An example is:
3851 P-02 1/28/02 10:31 AM Page 20

20 Chapter 2

<paragraph font='Times'>The running board fell off!</paragraph>

The ability to use more than one kind of quote is more than a simple convenience. It
provides an easy way to include quote marks inside the attribute value, such as:

<division title="Don't quit"></title>

Single and double quote characters, along with other special characters, can also be in-
serted by using the predefined entities describe in the “Entities” section of this chapter.
Attributes can be specified inside the short form of empty elements, like this:

<division title="Don't quit"/>

Comments
Anywhere you can put a tag, you can put a comment. A comment is normally ignored
by the process reading the document; it is only used to clarify the following or sur-
round XML document. A comment begins with the four-character sequence <!-- and
ends with the three-character sequence -->, such as:

<!-- This is the form of a simple comment -->

Because XML is a free-form language, a single comment can spread across several lines
and look like the following:

<!--
This is a comment that continues for more than
one line. This form can be used for a descriptive block
of text at the top or to try to make sense of some
some XML element that could be somewhat obscure.
-->

NOTE There’s one limitation to the contents of a comment. The two-character


sequence -- cannot be included in the body of a comment. This limitation
exists to accommodate very rudimentary parsers.

The Character Entities


An entity is a special name that you include in your XML text in such a way that it’s re-
placed with something else by the parser. For example, because the left angle bracket
character is used to define the start of a tag, you need to do something special to insert
it into your text. This is accomplished by using the predefined entity name lt. To use an
entity, precede it with an ampersand and terminate it with a semicolon. An example is:

<relation>Which proves that x &lt; a + b.</relation>


3851 P-02 1/28/02 10:31 AM Page 21

XML Document Format 21

Table 2.2 The XML Predefined Entities

ENTITY PRODUCES DESCRIPTION

&amp; & Ampersand


&apos; ' Single quote (apostrophe)
&gt; > Greater than
&lt; < Less than
&quot; " Double quote

Once this element is parsed, the resulting string will look like the following:

Which proves that x < a + b.

Table 2.2 lists the predefined entities that enable you to insert characters that would
otherwise cause problems with the parser.
You can use an entity to insert any character by specifying the Unicode or ASCII nu-
meric value of the character. This comes in handy when you want to insert a character
that has no key on your keyboard, such as a Greek character. This is particularly true of
Unicode because it includes the characters from every alphabet. The example in Listing
2.2 demonstrates the two different ways of specifying a Greek alphabet character:
Just like any other entity, when specifying a numeric value, you have to precede the
entity with an ampersand and terminate it with a semicolon. The # character is used to
indicate a numeric entity. If the first character in the number is a small x, the digits are
interpreted as hexadecimal digits; otherwise, they are assumed to be decimal digits.
You can define entities of your own by including their definitions in the DTD, as de-
scribed later in this chapter.

<?xml version="1.0"?>

<charents>
<fromhex>
The character &#x03A3; is an uppercase sigma.
</fromhex>
<fromdec>
The character &#931; is an uppercase sigma.
</fromdec>
</charents>

Listing 2.2 An XML Document Containing Special Characters


3851 P-02 1/28/02 10:31 AM Page 22

22 Chapter 2

<?xml version="1.0"?>

<progs>>
<function>
<![CDATA[
int frammis() {
if((a > b) && (a < 3.4))
return(1);
return(0);
}
]]>
</function>
</progs>

Listing 2.3 Using a CDATA Section for Special Formatting

The CDATA Section


If your text contains a lot of characters that could cause an XML parser problems, you
can get the parser to accept these characters directly without having to string together
a lot of the predefined entities. You can place the offending text inside a CDATA sec-
tion and the special characters will be ignored. The example in Listing 2.3 shows how
to include some source code without worrying about the individual characters:
The CDATA section begins with the nine-character string <![CDATA[ and ends
with the three-character sequence ]]>. The text must both be written exactly as you
want it to be formatted; no unwanted whitespaces can be inserted inside a CDATA sec-
tion. The text between the opening and closing of the section is completely ignored by
the parser. This means that the only character or sequence of characters that can’t be in-
cluded inside a CDATA section is the three-character string ]]>.

NOTE There is also a CDATA in DTD that should not be confused with this
one. They are for entirely different purposes and are not related.

DTD
The tags in an XML file are, by default, completely free form as long as the basic syn-
tax of the XML language is followed. You can, however, impose syntactic specifications
on each of the tag names by including a DTD in your XML document. Remember, a
DTD doesn’t add any meaning to the elements of a document; it only refines and ex-
tends the syntactic requirements. You can use the DTD to specify the type of data that
can be included in an element, the relative order and position of the elements, and
which elements can be nested inside other elements.
3851 P-02 1/28/02 10:31 AM Page 23

XML Document Format 23

The DTD syntax is quite different from that of the rest of the XML document. It pri-
marily consists of a list of all the tag names and a specification of the form each one will
take.
You can include the text of the DTD as part of the XML document itself, or you can
put the DTD into a separate file and simply refer to the file from the XML document.
The advantage of having the DTD as a separate file is that you can use it to define the
tag format for any number of XML documents. In fact, you can combine formats to-
gether by having a single XML document use the formatting defined in more than one
DTD file. The disadvantage of having the DTD as a separate file is that if you send the
XML document to someone else, they will normally need to use the same DTD file so
that the syntax of both the form and content of the elements can be recognized.

NOTE Even though the syntax of DTD is decidedly different from the rest of
XML, and the presence of DTD is optional, it’s still a part of the XML language.
The DTD text is read and processed by the same parser that reads and
processes the other parts of an XML document.

Single File
The document in Listing 2.4 shows how to use the DOCTYPE keyword to insert the text
of the DTD information inside the XML document.
Notice that standalone is set to "yes" in Listing 2.4 to indicate that everything is
contained in a single file. It would have been perfectly valid to set standalone to
"no" so that the parser would be ready to handle multiple files even though only one
file is used. Some parsers, however, will be more efficient if they know up front that
everything is going to be in one file.
To specify the DTD information, the keyword DOCTYPE is used as shown in Listing
2.4. Everything inside the opening bracket and closing bracket of the DOCTYPE decla-
ration is a part of the DTD. The DOCTYPE declaration itself requires the name of the root
element (in this example it’s the folks element) of the XML document.
In this example DTD there are five ELEMENT declarations. An ELEMENT declaration
specifies the contents of an element. The root element, named folks, is allowed to con-
tain only person elements. The number of person elements that can be contained is
specified by the asterisk modifier, which means there may be zero or more person el-
ements listed inside a folks element. And, because the person element is the only
thing specified for the folks element, a person element is the only thing it can con-
tain. Of course, the person element has a DTD definition of its own, but the content re-
quirements of a person element are independent of the content requirements of the
folks element.
Also in Listing 2.4, the person element must contain the three elements named
name, phone, and email. And because there is no occurrence modifier (like the aster-
isk in the folks element), each of these three elements must appear exactly once. Also,
because they’re separated by commas, they must appear in exactly the order in which
they appear in the DTD.
3851 P-02 1/28/02 10:31 AM Page 24

24 Chapter 2

<?xml version="1.0" standalone="yes"?>

<!DOCTYPE folks [
<!ELEMENT folks (person)*>
<!ELEMENT person (name, phone, email)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT email (#PCDATA)>
]>

<folks>
<person>
<name>Bertha D. Blues</name>
<phone>907 555-8901</phone>
<email>[email protected]</email>
</person>
<person>
<name>Fred Drew</name>
<phone>907 555-9921</phone>
<email>[email protected]</email>
</person>
</folks>

Listing 2.4 An XML Document with a DTD

The elements name, phone, and email are specified to contain #PCDATA. This
means they can only contain parse character data. In other words, they can only contain
a character string that does not contain any other elements. Because the character string
is parsed, it may contain things like the character entities that are predefined as part of
the XML language.

Multiple Files
The example in Listing 2.5 is the same as the one in Listing 2.4, except that the DTD is
stored in a separate file. An advantage to using this approach is that a separate file
makes it easy to create several documents based on the same DTD without having to
duplicate the DTD in every document. An additional advantage is that if the recipient
of a transmitted document already has a copy of the DTD, there’s no need to send an-
other one. In fact, because the DTD is only for syntax checking, an application knows
how to read the contents of a document formatted by the rules of a DTD. Therefore,
there is no need for the recipient to refer to the DTD at all unless, for some reason, the
receiver of the document does not trust the sender to format it correctly. The only pur-
pose of the DTD is to check the syntax of a document.
3851 P-02 1/28/02 10:31 AM Page 25

XML Document Format 25

<?xml version="1.0" standalone="no"?>

<!DOCTYPE folks SYSTEM "SimpleDoc.dtd">

<folks>
<person>
<name>Bertha D. Blues</name>
<phone>907 555-8901</phone>
<email>[email protected]</email>
</person>
<person>
<name>Fred Drew</name>
<phone>907 555-9921</phone>
<email>[email protected]</email>
</person>
</folks>

Listing 2.5 An XML Document with an External DTD

The DOCTYPE keyword still serves the same purpose as before, but this time the
SYSTEM keyword is used to precede the name of the file containing the DTD speci-
fications. The name of the DTD file is in the same directory as this XML file, is named
SimpleDoc.dtd, and contains the content shown in Listing 2.6.
This file contains only the definitions that go inside the DOCTYPE block, but not the
DOCTYPE declaration itself (DOCTYPE declarations are discussed in detail in the fol-
lowing sections of this chapter). It does, however, have an XML declaration at the top.
Also, the DTD file must include the encoding because the content of the file is going to
be read and analyzed by the parser, and the parser needs to know what encoding
scheme is being used.

The DOCTYPE Inline Declaration


The DOCTYPE inline declaration is the simplest form of DOCTYPE included in the XML
file, as demonstrated in Listing 2.4. This form of DOCTYPE includes all of the DTD

<?xml version="1.0" encoding="US-ASCII"?>

<!ELEMENT folks (person)*>


<!ELEMENT person (name, phone, email)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT email (#PCDATA)>

Listing 2.6 A Simple DTD File


3851 P-02 1/28/02 10:31 AM Page 26

26 Chapter 2

declarations directly inline as a part of the XML document. Its basic form is shown in
the following example:

<!DOCTYPE folks [
<!ELEMENT folks (person)*>
. . .
]>

All of the DTD declarations are included between the DOCTYPE opening and closing
brackets. This can include any combination of ELEMENT, CDATA, ATTLIST, ENTITY,
IGNORE, and INCLUDE. And, of course, there can be any number of comments inter-
mixed with the DTD definitions.

The DOCTYPE SYSTEM Declaration


Using the SYSTEM keyword enables you to specify the name of a file with either a
relative or absolute URI. The following is an example of using a relative URI to spec-
ify the location of a file named inhere.dtd that’s in the same directory as the XML
document:

<!DOCTYPE folks SYSTEM "inhere.dtd">

The following example, another relative URI, specifies the file named insub.dtd in
a local subdirectory named diction:

<!DOCTYPE folks SYSTEM "diction/insub.dtd">

An absolute URI can be used to specify the address of a file anywhere on the Internet.
The following example shows the URI of a DTD document named SimpleDoc.dtd
that’s stored and readily available on the Internet. This very simple technique can be
used to make sure that everyone is using the same DTDs to define the formats of the
same set of documents:

<!DOCTYPE folks SYSTEM "http://www.belugalake/xdox/SimpleDoc.dtd">

NOTE The URI string will accept both forward and backward slashes to
accommodate the naming requirements of different operating systems.

It is possible to use a SYSTEM DTD and, at the same time, include some DTD modi-
fications that apply to the local document. You can include any statement that could
also be written directly into the existing DTD. That is, you cannot override and replace
an existing definition, but you can add definitions to the DTD. For example, you can
add a new attribute definition for an existing tag, as in Listing 2.7.
This example uses the same DTD file that was used in previous examples, but this
time the phone element is modified by ATTLIST to add the option of specifying an
extension attribute. Details of ATTLIST are described later in this chapter.
3851 P-02 1/28/02 10:31 AM Page 27

XML Document Format 27

<?xml version="1.0" standalone="no"?>


<!DOCTYPE folks SYSTEM "SimpleDoc.dtd" [
<!ATTLIST phone extension CDATA #IMPLIED>
]>

<folks>
<person>
<name>Bertha D. Blues</name>
<phone extension="409">907 555-8901</phone>
<email>[email protected]</email>
<fax>907 555-3333</fax>
</person>
</folks>

Listing 2.7 Adding an Attribute Definition to an Existing DTD

The DOCTYPE PUBLIC Declaration


The PUBLIC keyword works somewhat like the SYSTEM keyword, but with something
added. The intention of this form is that it be used with a standard DTD that’s been
published and made widely available. Not only does this form of the DTD specification
have a location (as with SYSTEM), but it also has a name. At first glance the name may
appear to be a URI, but it isn’t. It’s in a special format laid out as follows:

prefix//owner//description//language ID

If the prefix is ISO, the DTD is an approved ISO standard. If the prefix is +, the DTD
is an approved standard, but it is not an ISO standard. If the prefix is -, the DTD is an
ISO standard proposal that has not yet been approved. The owner is the name, or an
acronym, identifying the owner of the DTD specification. The description is a brief de-
scription of the DTD. The language ID is a two-letter ISO 639 specification of the lan-
guage of the DTD.
The name of the DTD comes before the URI that specifies its location. The following
example specifies that the DTD is to be the strict version of the W3C definition of
HTML version 4.01:

<?xml version="1.0" standalone="no" ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"


"http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
The heading of the XHTML page.
</head>
3851 P-02 1/28/02 10:31 AM Page 28

28 Chapter 2

<body>
The body of the XHTML page.
</body>
</html>

In this example the name specifies that the DTD is a proposed ISO standard owned by
the W3C organization. The descriptive name of the DTD is DTD HTML 4.01 and the
language is EN (English). Judging by the URI, it seems this DTD is a very strict imple-
mentation of the standard; there are other versions at the same site of both transitional
and loose implementations.
Also, as you would expect, you can make local additions to the DTD using the same
technique as described earlier for the SYSTEM declaration.

Comments
It doesn’t matter whether the DTD text is in the same file or in a separate file; the for-
mat of comments is the same as in any other section of an XML document. A valid com-
ment looks like this:

<!-- Comments in DTD are in the same format as the rest of XML-->

The ELEMENT Declaration


The ELEMENT keyword is used to define the form of a tag in the XML document. It
specifies both the tag name of the tag and the form of the tag content. An element def-
inition consists of the ELEMENT keyword, followed by the name of the tag, followed by
the rule that determines the content of the element.

The ANY Element


The keyword ANY can be used when you wish to define the tag name of an element but
leave all the formatting of element content unspecified. An element defined this way
can include any text and other elements (as long as all included elements are also valid)
between its opening and closing tags. For example, the following specifies that the tag
named nolimit is declared to be completely free form:

<!ELEMENT nolimit ANY>

This means that, as long as the syntax is correct, anything goes. All of the following are
valid nolimit elements:

<nolimit>Text is okay for an ANY</nolimit>


<nolimit></nolimit>
<nolimit/>
<nolimit>Embedding<nolimit>another</nolimit>tag is okay</nolimit>
3851 P-02 1/28/02 10:31 AM Page 29

XML Document Format 29

The EMPTY Element


It is possible to specify that an element to contain no data by defining it this way:

<!ELEMENT hr EMPTY>

An empty element is one that contains no text and no other elements. The following ex-
amples show the two possible forms of an empty element:
<hr></hr>
<hr/>

Note that even though an empty element cannot contain data between the tags, it
can still have attributes defined for it. Details on declaring and using attributes are de-
scribed later in this chapter. The following is an example of defining and using an op-
tional attribute with the hr element:

<!ELEMENT hr EMPTY>
<!ATTLIST hr style #IMPLIED>
. . .
<hr style="reversed"/>

An Element with Mixed Content


The mixed content element definition allows a free mixture of text with any of the
listed XML tags. To specify that character text may be included between the tags of an
element, the keyword #PCDATA can be used. The following example specifies that the
element named textonly can only contain text:

<!ELEMENT textonly (#PCDATA)>

#PCDATA must be included in parentheses. The name PCDATA is short for parsed
character data, so-called because the parser actually reads through the text to find em-
bedded tags or entities. At the very least, the parser has to scan the text to find the clos-
ing tag. The textonly tag, however, does not allow for any embedded tags; it can only
be used for text as follows:

<textonly>Now is the time</textonly>

If you wish to specify that the content can be text intermixed with tags, you can use
the vertical bar to separate the items and add an asterisk at the end to specify that the
items in the parentheses can each be repeated any number of times as shown in the fol-
lowing example:

<!ELEMENT textag (#PCDATA | hr)*>

An element of the type textag can contain text with an unlimited number of hr el-
ements embedded in it. You can extend this format to specify any number of element
names that can be embedded in the text by listing them this way:
3851 P-02 1/28/02 10:31 AM Page 30

30 Chapter 2

<!ELEMENT textags (#PCDATA | hr | b | br | bold | italic)*>

The vertical bars between the items indicates that the content can be any one of the
items, and the asterisk at the end indicates that the item can be repeated any number
of times. The result is that the content can be any amount of text with the named ele-
ments embedded in it any order.

An Element with Element Content


An element that contains only other elements is referred to as having element content.
By using parentheses and the operators that specify the number of times each element
is to occur, it’s possible to specify any desired pattern of elements. The following ex-
ample specifies that the content of the element pkone can be any one of three elements:

<!ELEMENT name (#PCDATA)>


<!ELEMENT address (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT pkone (name | address | phone)>

The vertical bar between two elements is the OR operator, and it indicates that one
or the other may be used, but not both. As you can see, the OR operator can be used in
a sequence specifying that only one of the members of the list can be selected. The fol-
lowing example specifies that the content of pkall must be all three of the named el-
ements:

<!ELEMENT pkall (name , address , phone)>

A comma between two elements is an AND operator, which indicates that both ele-
ments must be included, and they must be included in the order in which they are
listed. The pkall element must include the elements name, address, and phone,
and they must appear in that order. The following examples demonstrate how these
two forms can be combined to create a more complicated rule:

<!ELEMENT pkchoose (name, address, (phone | email))>

Using these element definitions, the following elements are valid:

<pkone>
<name>Fred Drew</name>
</pkone>
<pkone>
<phone>555-1028</phone>
</pkone>
<pkall>
<name>Fred Drew</name>
<address>1313 Luck St</address>
<phone>555-1028</phone>
3851 P-02 1/28/02 10:31 AM Page 31

XML Document Format 31

</pkall>
<pkchoose>
<name>Fred Drew</name>
<address>1313 Luck St</address>
<phone>555-1028</phone>
</pkchoose>
<pkchoose>
<name>Quintus Drew</name>
<address>1315 Luck St</address>
<email>[email protected]</email>
</pkchoose>

The operators listed in Table 2.3 specify how often an item may be repeated. For ex-
ample, the following definition specifies that the email address is optional, but there
must be at least one (and possibly more) phone number:

<!ELEMENT contact (name , email? , phone+)>

The occurrence operators can also be applied to sets of items in parentheses. For ex-
ample, the following specifies that a chlist element can contain any number of names
and addresses. Each name and address must be accompanied by at least one phone or
email element but can have any number of phone and email elements:

<!ELEMENT chlist (name, address, (phone | email)+)*>

The ATTLIST Declaration


The ATTLIST keyword can be used to specify one or more attributes that can be used
as part of an element. This is done by specifying the element name, the name of the new
attribute, and some rules about the value that can be assigned to the attribute. For ex-
ample, for an element named rectangle to have a couple of attributes, they could be
defined in the DTD as follows:

<!ELEMENT rectangle EMPTY>


<!ATTLIST rectangle height CDATA #IMPLIED>
<!ATTLIST rectangle width CDATA #IMPLIED>

Table 2.3 The Occurrence Operators

OPERATOR DESCRIPTION

? The item may be omitted but, if included, it can only appear once.
* The item may be omitted and, if included, it can be repeated any
number of times.
+ The item must be included at least once, and it may be repeated
any number of times.
none The item must be included once.
3851 P-02 1/28/02 10:31 AM Page 32

32 Chapter 2

A single ATTLIST entry can also be used to declare multiple tags for the same ele-
ment. An example is:

<!ELEMENT rectangle EMPTY>


<!ATTLIST rectangle height CDATA #IMPLIED
width CDATA #IMPLIED>

In the XML code, a valid rectangle element is required to include the two attrib-
utes declared with it, and it could look like this:

<rectangle width="100" height="200"/>

When defining an attribute, it’s necessary to specify the data type and, possibly, an ini-
tial value or set of possible values. Table 2.4 lists the possible default declarations used to
specify the requirement, or lack of requirement, imposed on attributes. Table 2.5 de-
scribes the keywords used to specify the type of data and gives an example of each one.

The ENTITY Declaration


An ENTITY declaration can be used to define textual substitution that will be made by
the parser. If, for example, you wanted to insert a company name automatically
throughout a document, you could do so by using the entity &company; you could de-
fine it as follows:

<!ENTITY company "International Widget Inc.">

The entity definition cannot be made inside an element, so it must come before the
root element of the document. Once this entity has been defined, the string “Interna-
tional Widget Inc.” will be inserted automatically wherever you use the entity, such as:

<customer>&company;</customer>

You can define a number of entities in a single document and use them to general-
ize the contents of the document itself. That is, by just changing the values of the enti-
ties, the content of the document would change. Just as was done with the predefined

Table 2.4 Declaring Validity Constraints of an Attribute

CONSTRAINT DESCRIPTION

#IMPLIED The attribute may used in an element of this type, but it is not
required.
#REQUIRED This attributed must be specified for all elements of this type.
#FIXED This is always followed by a quoted string that is the only
value that can be assigned to the attribute.
3851 P-02 1/28/02 10:31 AM Page 33

XML Document Format 33

Table 2.5 Attribute Types

TYPE DESCRIPTION EXAMPLE

CDATA If the attribute is specified in an <!ATTLIST elename altname


element, its value can be any CDATA #REQUIRED>
quoted string. <elename altname="fred"/>

ID The name can be used as the <!ATTLIST locdef id


target of a link from an IDREF of ID #IMPLIED>
another element inside the docu- <locdef id="id8801"/>
ment. In the future, this could also
be a target for links from outside
the document. An ID must be
declared as either #IMPLIED
or #REQUIRED. An element can
only have one ID defined for it.
IDREF This is the link from this element <!ATTLIST locref taglink
to an element with an ID attribute. IDREF #IMPLIED>
The value provided for this tag <locref taglink="id8801"/>
makes the link by matching the
value specified on an ID tag
somewhere else in this document.
IDREFS This is the same as IDREF except <!ATTLIST locref taglink
that it can be used to specify IDREFS #IMPLIED>
multiple references. <locref taglink="id8801 id6422
id4733"/>

ENTITY The value must match an unparsed <!ATTLIST picture img


entity declared somewhere in the ENTITY #REQUIRED>
DTD. An unparsed entity is created <picture img="front"/>
by a NOTATION declaration.
ENTITIES The same as ENTITY except that <!ATTLIST picture img
it can be used to match multiple ENTITIES #REQUIRED>
unparsed entities. <picture img="front back side
top"/>

NMTOKEN The value must be a valid name <!ATTLIST ident name


made up of letters, digits, periods, NMTOKEN #REQUIRED>
hyphens, and underscores. It may <ident name="eggplant"/>
even contain a colon. It purpose is
to simply specify a name.
NMTOKENS This is the same as NMTOKEN <!ATTLIST ident namelist
except that it can specify a list NMTOKENS #REQUIRED>
of names. <ident namelist="eggplant
grunion raspberry"/>
3851 P-02 1/28/02 10:31 AM Page 34

34 Chapter 2

<?xml version="1.0"?>

<!ENTITY company "International Widget Inc.">


<!ENTITY address "896 Grand Parkway">

<agreement>
<intro>
The company name is &company; with main offices
located at &address;.
</intro>
</agreement>

Listing 2.8 A Document Defining and Using Entities

entities, you can mix your own entities with text. The document in Listing 2.8 includes
the definition of some entities and some text with a pair of entities embedded in it.
An even more generalized treatment of form of ENTITY is to store the substitution
text in a separate file. By doing so, you’ll need only to change the content of the entity
file to make a modification to the document. This is done using the keyword SYSTEM
as in the following:

<!ENTITY company SYSTEM "companyName.txt">

Just as with the SYSTEM keyword in the DOCTYPE declaration, the file can be located
anywhere on the Internet.

Parameter Entities
A parameter entity can be used to make substitutions in the DTD instead of in the XML
document. A normal entity does not cause substitutions to be made inside the DTD, so
there’s no way for the parser to recognize any of the DTD keywords. For example, the
following will not work:

<!ENTITY cdreq "CDATA #REQUIRED">


<!ELEMENT post ANY>
<!ATTLIST post height &cdreq;> <!-- Error -->

A parameter entry can be used to make the substitution work inside the DTD. To
create a parameter entity, you’ll need to insert a percent sign in front of the name of the
entity being defined. An example is:

<!ENTITY % cdreq "CDATA #REQUIRED">


<!ELEMENT post ANY>
<!ATTLIST post height %cdreq;>
Another random document with
no related content on Scribd:
object. But, if I were you, I would rather work my own way up in the
world than connect myself with such a man as Temple. The first time
he wanted something to fidget himself about, he would be for calling
out of your hands all he had lent you.”
“One would almost bear such a risk,” said Arthur, “for the sake of
the settlement. My poor sister makes the best of matters by talking
everywhere of the quantity of labour her husband employs. But I
think she must see that that employment must soon come to an end
if no returns issue from it. I am sure I should be glad to employ
much more labour, and in a way which would yield a maintenance
for a still greater quantity next year, if I had the laying out of the
money Temple wastes on his caprices. I am not complaining, father,
on my own account. My hardest time is over, and I shall soon be
doing as well as I could wish. I am now thinking of the interests of
the place at large. It seems too hard that the richest man among us
should at the same time keep away new settlers by holding more
land than he can cultivate, waste his capital, instead of putting it out
to those who would employ it for his and the common good, and
praise himself mightily for his liberal expenditure, holding the entire
community obliged to him for it, every time he buys a new luxury
which will yield no good beyond his own selfish pleasure.”
“I am afraid you think the community has little to thank me for,
Arthur? Perhaps, in our present state of affairs, the money I have
ought to go towards tilling the ground, instead of exploring the
heavens.”
"My dear sir, no. I differ from you entirely. You do not live beyond
your income, nor——"
“Give your mother the credit of that, Arthur. But for her, my little
property would have flown up to the moon long ago.”
“But, father, I was going to say that what I and others here
produce is but the means of living, after all. It would be deplorable
to sacrifice the end to them.”
“What end? Do you mean the pleasure of star-gazing? I should be
delighted to hear that.”
"Pleasure,—whether of star-gazing, or of any thing else that is
innocent and virtuous,—that is really happiness. If Temple is really
happy over his foreign wines, I am sure I have no more objection to
his drinking them than to my men enjoying their cider. Let it be his
end, if he is capable of no higher, as long as his pleasures do not
consume more than his income. Much more may I be willing that
you should enjoy your star-gazing, when out of the gratification to
yourself arises the knowledge which ennobles human life, and the
truth for which, if we do not live now, we shall assuredly live
hereafter."
“I have always trusted, Arthur, that the means which have been
bestowed upon me would not prove to be lost. Otherwise, I would
have taken my axe on my shoulder, and marched off to the forest
with you.”
"Father, it is for such as you that forests and prairies should be
made to yield double, if the skill of man could ensure such
fruitfulness. It is for such as you that the husbandman should lead
forth his sons before the dawn, and instruct them to be happy in
toiling for him whose light in yon high place is yet twinkling,—who
has been working out God’s truth for men’s use while they slept."
“Our husbandmen are not of the kind you speak of, Arthur. I see
them look up as they pass, as if they thought this high chamber a
folly of the same sort as Temple’s Chinese alcove.”
“I think you mistake them, sir. I can answer for those with whom I
have to do. They see all the difference between Temple’s restless
discontent and your cheerfulness. They see that he has no thought
beyond himself, while you have objects of high and serious interest
ever before your mind’s eye; objects which, not comprehending,
they can respect, because the issue is a manifestation of wisdom
and benignity.”
“Enough! enough!” cried the doctor. "I have no complaint to make
of my neighbours, I am sure. I should be a very ungrateful man, if I
fancied I had. I am fully aware of the general disposition of men to
venerate science, and to afford large aid to those who pursue it, on
a principle of faith in its results. My belief in this is not at all shaken
by what befel me in England; but, as I have appeared here
accidentally,—a philosopher suddenly lighting in an infant community
instead of having grown up out of it, it was fair to doubt the light in
which I am regarded. If the people hated me as a magician, or
despised me as an idle man, I think it would be no wonder."
“I am glad you hold your faith, father, in the natural veneration of
society for the great ends of human life. I believe it must be a strong
influence, indeed, which can poison men’s minds against their
legislators, and philosophers, and other wise men who neither dig
nor manufacture. I believe it must be such a silver tongue as never
yet spoke that could persuade any nation that its philosophers are
not its best benefactors.”
"True. It was not the English nation that drove me hither; and
those who did it never complained of my pursuits,—only of what
they supposed my principles. I wish I could bear all the sorrow of
the mistake."
“Be satisfied to let them bear some of it, father. It will help to
guard them against a repetition of it. I am sure your own share is
enough.”
"In one sense it is, Arthur. Do you know, I find myself somewhat
changed. I perceive it when I settle myself down to my pursuits; and
to a greater extent than I anticipated. It may be owing in part to the
want of the facilities I had enjoyed for so many years, and never
thought to part with more. I sometimes wonder whether I should be
the same man again at home, among——But let all that pass. What
I was thinking of, and what your mother and I oftenest think of, is
the hardship of your having to bear a part,—so large a part in our
misfortune. I should wonder to see you toiling as you do, from
month to month,—(for I know that wealth is no great object with
you,)—if I did not suspect——But I beg your pardon. I have no right
to force your confidence."
“Go on, father.”
“Well, to say the truth, I suspect that you left something more
behind you than you gave us reason to suppose. If you had not
come of your own free choice, this idea would have made both your
mother and me very unhappy.”
“I have hopes that she will come, father. I have been waiting to
tell you, only for a prospect of the time when I might go for her.
Nothing is settled, or I would have told you long ago; but I have
hopes.”
Dr. Sneyd was so long silent, thinking how easily the use of some
of Temple’s wasted money would have completed Arthur’s happiness
ere this,—benefiting Temple and the whole community at the same
time,—that his son feared he was disappointed. He had no
apprehension of his being displeased at any part of his conduct.
“I hoped the prospect would have given you pleasure, father,” he
said, in a tone of deep mortification.
"My dear son, so it does—the greatest satisfaction, I assure you;
though, indeed, I do not know how you were to become aware of it
without my telling you. I know my wife’s opinion of her to be the
same as my own. I only hope she will be to you all that may repay
you for what you have been to us: indeed, I have no doubt of it."
Arthur was perfectly happy; happy enough to observe that the
clouds were parting, and that,—as science had been so lately
pronounced the great end for which his father was living,—it was a
pity his observations should not be renewed.
“If science be the great object we think it,” observed the doctor
the next time he was obliged to suspend his labours, “it seems
strange that it should be pursued by so few. At present, for one who
devotes himself to the end, thousands look not beyond the mere
means of living. I am not afraid to call it the end to you, though I
would not have done so in my pulpit this morning without
explanation. We understand one another.”
"Perfectly; that since the full recognition of truth is virtue, science
is the true end. I hope, I believe, I discern the method by which
more and more labour will be withdrawn from the means to be
transferred to the end. For a long time past,—ever since I have been
in the habit of comparing you and your pursuits with the people
about you and their pursuits—ever since I came here,—I have been
arriving at my present conviction, that every circumstance of our
social condition,—the most trifling worldly interest of the meanest of
us,—bears its relation to this great issue, and aids the force of
tendency towards it."
“You have come hither for something worth gaining, then: it is
worth while to cross land and sea for such a conviction. Can I aid
you with confirmation from the stars?”
"No doubt; for all knowledge, come whence it may,—from
incalculable heights or unfathomable depths,—all new knowledge of
the forces of nature affords the means of setting free a quantity of
human labour to be turned to new purposes. In the infancy of the
race, the mind had no instruments but the unassisted hands. By
degrees, the aid of other natural forces was called in; by degrees,
those forces have been overruled to more and more extended
purposes, and further powers brought into subjection, setting free,
at every new stage of acquisition, an immense proportion of human
labour, and affording a glimpse,—almost too bright to be met by our
yet feeble vision,—of times when material production—the means of
living, shall be turned over to the machinery of nature, only
superintended by man, whose life may then be devoted to science,
‘worthy of the name,’ which may, in its turn, have then become the
means to some yet higher end than is at present within our ken."
“In those days, then, instead of half-a-dozen labourers being
virtuously employed in production for themselves and one
unproductive philosopher, the six labourers will themselves have
become philosophers, supported and cherished by the forces of
nature, controlled by the intellect of perhaps one productive
labourer.”
“Just so; the original philosopher being the cause of this easy
production by his ascertainment of the natural forces in question.
This result is merely the protraction of the process which has been
going on from the earliest infancy of the race. If Noah, in his first
moonlight walk upon Ararat, could have seen mirrored in the watery
waste the long procession of gigantic powers which time should lead
forth to pass under the yoke of man, would he not have decided (in
his blindness to the new future of man) that nothing would be left
for man to do?”
“Probably. And in order to exhibit to him the whole case, he must
be carried forward to man’s new point of view.”
“And so it will be with some second Noah, whose happier lot it
shall be to see knowledge cover the earth, bearing on its bosom all
that is worthy of the new heavens and new earth; while all that is
unworthy of them is sunk and lost. By the agency of his gigantic
servants he may be raised to that pinnacle of the universe whence
he may choose to look forth again, and see what new services are
appointed to man, and who are the guides and guardians allotted to
his higher state.”
"And what will he behold?——But it is foolish to inquire. One must
be there to know."
"To know fully. But though we can but barely speculate upon what
he will see, we may decidedly pronounce upon what he will not see.
We cannot tell how many galaxies will be perceived to complete the
circle of Nature’s crown, nor what echoes of her diapason shall be
wafted to the intent spirit. We cannot tell how near he may be
permitted to approach to behold the evolution of a truth from
apparent nothingness, as we are apt to fancy a seraph watches the
creation of one of yonder worlds—first distinguishing the dim
apparition of an orb emerging from the vacuum, then seeing it
moulded into order, and animated with warmth, and invested with
light, till myriads of adorers are attracted to behold it sent forth by
the hand of silence on its everlasting way. We cannot tell to what
depth man may then safely plunge, to repose in the sea-caves, and
listen to the new tale that its thunders interpret, and collect around
him the tributaries of knowledge that come thronging down the
green vistas of ocean light. We cannot tell what way will be opened
before him to the dim chambers of the earth, where Patience
presides, while her slow and blind agents work in dumb concert from
age to age, till, the hour being come, the spirit of the volcano, or the
angel of the deluge, arrives to burst their prison-house. Of all these
things we can yet have but a faint conception; but of some things
which will not be we can speak with certainty."
“That when these inanimate powers are found to be our best
servants, the immortal mind of man will be released from the
drudgery which may be better performed by them. Then, never
more will the precious term of human life be spent in a single
manual operation; never more will the elastic limbs of children grow
rigid under one uniform and excessive exercise; never more will the
spirit sit, self-gnawing, in the fetters to which it has been
condemned by the tyranny of ignorance, which must have its
gratifications. Then bellows may breathe in the tainted streams of
our factories, and human lungs be spared, and men’s dwellings be
filled with luxuries, and no husbandman be reduced from his
sovereignty of reason to a similitude with the cattle of his pastures.
But much labour has already been set free by the employment of
the agency of nature; and how little has been given to science!”
“It seems as if there must ever be an intermediate state between
the discovery of an instrument and its application to its final use. I
am far from complaining, as you know, of the nature of human
demands being what it has been, as, from time to time, liberated
industry has afforded a new supply. I am far from complaining that
new graces have grown up within the domains of the rich, and that
new notions of convenience require a larger satisfaction day by day.
Even when I perceive that a hundred heads and hands are
necessary to the furnishing forth of a gentleman’s equipage, and
that the wardrobe of a lady must consist of, at least, a hundred and
sixty articles, I am far from wishing that the world should be set
back to a period when men produced nothing but what was
undeniably essential.”
“You would rather lead it on to the time when consumption will
not be stimulated as it is at present?”
"When it shall be of a somewhat different kind. A perpetual
stimulus seems to me to be provided for by labour being more and
more set at liberty, since all the fruits of labour constitute at once
the demand and the supply. But the desires and tastes which have
grown up under a superabundance of labour and a dearth of science
are not those which may be looked for when new science (which is
as much the effect as the cause of new methods of production) shall
have opened fresh worlds to human tastes. The spread of luxury,
whether it be pronounced a good or an evil, is, I conceive, of limited
duration. It has served, and it still serves, to employ a part of the
race and amuse another part, while the transition is being made
from one kind of simplicity to another,—from animal simplicity to
intellectual simplicity."
“The mechanism of society thus resembles the mechanism of
man’s art. What was done as a simple operation by the human arm,
is effected as a complicated operation by instruments of wood and
steel. But the time surely comes when this complexity is reduced,
and the brute instrument is brought into a closer and a still closer
analogy with the original human mechanism. The more advanced
the art, the simpler the mechanism.”
"Just so. If, in respect of our household furniture, equal purposes
of convenience are found to be answered by a smaller variety of
articles, the industry which is thus released will be free to turn to the
fine arts,—to the multiplication of objects which embody truth and
set forth beauty,—objects which cannot be too extensively
multiplied. If our ladies, at the same time, discover that equal grace
and more convenience are attained by a simpler costume, a more
than classical simplicity will prevail, and the toil of operatives will be
transferred to some higher species of production."
“We should lose no time, then, in making a list of the present
essentials of a lady’s wardrobe, to be preserved among the records
of the race. Isaiah has presented one, which exhibits the maidens of
Judea in their days of wealth. But I believe they are transcended by
the damsels of Britain.”
"I am sure the British ladies transcend the Jewish in their method
of justifying their luxury. The Jewesses were satisfied that they
enjoyed luxury, and looked no farther. The modern ladies extol it as
a social virtue,—except the few who denounce the very enjoyment
of it as a crime. How long will the two parties go on disputing
whether luxury be a virtue or a crime?"
“Till they cease to float themselves on the surface of morals on
the support of old maxims of morality; till they look with their own
eyes into the evidence of circumstance, and learn to make an
induction for themselves. They will see that each side of the
question has its right and its wrong; that there is no harm, but much
good in enjoyment, regarded by itself; and that there is no good, but
much harm in causing toil which tends to the extinction of
enjoyment.”
“In other words, that Dr. B’s pleasure in his picture gallery is a
virtuous pleasure while he spends upon it only what he can well
spare; and that Temple’s hot-houses are a vicious luxury, if, as we
suspect, he is expending upon them the capital on which he has
taught his labourers to depend as a subsistence fund.”
“Exactly; and that the milk-maid may virtuously be married in the
silk gown which her bridegroom thinks becoming, provided it is
purchased with her surplus earnings; while an empress has no
business with a yard of ribbon if she buys it after having parted with
the last shilling of her revenue at the gaming-table. Silk is beautiful.
If this were all, let every body wear silk; but if the consequence of
procuring silk be more pain to somebody than the wearing of silk
gives pleasure, it becomes a sin to wear silk. A thriving London
tradesman may thus innocently dress his wife and nine daughters in
Genoa velvet, while the spendthrift nobleman may do a guilty deed
in arraying himself in a new fashion of silk hose.”
"Our countrywomen may be expected to defend all luxurious
expenditure as a virtue, while their countrymen,—the greyheaded as
well as youths,—are overheard extolling a war expenditure as a
public good. Both proceed on the notion that benefit resides in mere
consumption, instead of in the reproduction or in the enjoyment
which results; that toil is the good itself, instead of the condition of
the good, without which toil is an evil."
“If war can be defended as a mode of expenditure by any but
gunsmiths and army clothiers, there is no saying what curse we may
not next find out to be a blessing. Of all kinds of unproductive
consumption, that occasioned by war is the very worst. Life, and the
means of life, are there extinguished together, and one might as well
try to cause the resurrection of a slain army on the field of battle, as
hope for any return to the toil of the labourers who equipped them
for the strife. The sweat of the artisan falls as fruitless as the tears
of the widow and orphan. For every man that dies of his wounds
abroad, there is another that pines in hunger at home. The hero of
to-day may fancy his laurels easily won; but he ought to know that
his descendants of the hundredth generation will not have been able
to pay the last farthing of their purchase-money.”
"And this is paid, not so much out of the luxuries of the rich as the
necessaries of the poor. It is not so much one kind of unproductive
consumption being exchanged for another as a productive
consumption being stinted for the sake of an unproductive. The rich
may contribute some of their revenue to the support of a war, but
the middling classes give,—some a portion of their capital, and
others the revenue of which they would otherwise make capital,—so
that even if the debts of a war were not carried forward to a future
age, the evil consequences of an abstraction of capital are."
"It appears, however, as if unproductive consumption was much
lessened at home during a war. One may see the difference in the
very aspect of the streets in London, and yet more in the columns of
newspapers. Puffing declines as soon as a war breaks out,—not that
puffing is a sign of any thing but a glut of the article puffed,—but
this decline of puffing signifies rather a cessation of the production
of the community than such a large demand as needs no
stimulating."
"Yes; one may now see in London fire-arms or scarlet cloth
exhibited at the windows of an establishment where, during the
peace, might be found ‘the acmè of paper-hanging;’ and where
might formerly be had floor-cloth of a marvellous number of yards
without seam, whose praises were blazoned in large letters from the
roof to the ground, ball cartridges are piled, and gunpowder stands
guarded, day and night. Since gluts work their own cure, and puffing
comes of gluts, puffing is only a temporary absurdity. Long may it be
before we are afflicted with it here!"
"Afflicted?—Well! looked at by itself, perhaps it is an affliction, as
all violations of truth, all exhibitions of folly, are; but one may draw
pleasure too from every thing which is a sign of the times."
“O, yes; there is not only the strong present pleasure of
philosophising on states of society, but every indication of what it
serves to the thinker, at the same time, as a prophecy of better
things that shall be. But, do you not find it pleasanter to go to
worship, as we went this morning, through green pastures and by
still waters, where human industry made its appeals to us in
eloquent silence, and men’s dwellings bore entire the aspect of
sabbath repose, than to pass through paved streets, with a horizon
of brick-walls, and tokens on every side, not only of week day labour,
but of struggle for subsistence, and subservience for bread? The
London shopkeepers do not remove their signs on a Sunday. If one
catches a glimpse here and there of a spectacled old gentleman
reading his Bible in the first-floor parlour, or meets a train of spruce
children issuing from their father’s door at the sound of the church-
bell, one sees, at the same time, that their business is to push the
sale of floor-cloth without seam, and to boast of the acmè of paper-
hanging.”
"There may be more immediate pleasure in the one Sabbath walk
than in the other, Arthur, but they yield, perhaps, equally the aliment
of piety. Whatever indicates the condition of man, points out, not
only the species of duty owing to man, but the species of homage
due to God,—the character of the petitions appropriate to the
season. All the methods of going to worship may serve the purpose
of preparation for the sanctuary. The nobleman may lean back in his
carriage to meditate; the priest may stalk along in reverie,
unconscious of all around him; the citizen-father may look with pride
on the train of little ones with whom he may spend the leisure of this
day; and the observing philanthropist may go forth early and see a
thousand incidents by the way, and all may alike enter the church-
door with raised and softened hearts."
“And all listen with equal faith to the promise of peace on earth
and good-will to men?”
“Yes, and the observer not the least, if he observe for holy
purposes.”
"O, father, think of the gin-shop and the news-office that he must
pass by the way! They are infinitely worse than the visible puffery.
Think of the thronged green-grocer’s shop, where you may see a
widow in her soiled weeds, flushed with drink, careless of the little
ones that cling to her gown, hungering as they are for the few
potatoes which are all she can purchase after having had her
morning dram!—Think of the father cheapening the refuse of the
Saturday’s market, and passing on, at last, wondering when his pale
family will again taste meat! Think of the insolent footmen, impeding
the way to the church-door, while they amuse themselves with the
latest record of licentiousness in the paper of the day!"
"I have often seen all this, Arthur, and have found in it——"
"Nothing that necessarily hardens the heart, I know; on the
contrary, the compassion excited is so painful that devotion is at
times the only refuge. But as for the congeniality——"
“What is the value of faith, if it cannot assimilate all things to
itself? And as for Christian faith, where and amidst what
circumstances did it arise? Was it necessary, in going up to the
temple, to overlook the blind beside the way, and to stop the ears
when the contention of brethren was heard, and to avoid the proud
Pharisee and the degraded publican? Was the repose of the spirit
broken when an adultress entered the sacred precincts? Were the
avenues to the temple blocked up that the holy might worship in
peace? And when they issued forth, were they sent home to their
closets, forbidden to look to the right hand or to the left for fear of
defilement?”
“If so, it was by order of the Pharisees. You are right, father. The
holiest did not even find it necessary to resort to mountain solitudes,
or to the abodes of those who were pure as themselves, for the
support of their faith or the repose of their devotion. Aliment for
piety was found at the table of the publican, and among the
sufferers beside Bethesda. To the pure every emotion became a
refining process, and whatever was not found congenial was made
so. It may certainly be the same with the wise and the benignant of
every age.”
“It is indeed a halting faith which dreads as common that which
God has cleansed and sanctified; and where is God’s own mark to be
recognized but in the presence of joy and sorrow, of which he is the
sole originator and distributor? Whatever bears a relation to joy and
sorrow is a call to devotion; and no path to the sanctuary is more
sacred than another, while there are traces of human beings by the
way.”
“You prefer then the pastures which tell of our prosperity to the
wilds of the prairie; and I observed that you dwelt upon the portraits
of familiar faces before you left your study this morning.”
"I did; and many a time have I dwelt quite as earnestly on strange
faces in which shone no friendship for me, and no consciousness of
the objects of the day. I read in their human countenance,—human,
whether it be vile or noble,—the promise, that as all things are for
some use, and as all men contribute while all have need, the due
distribution will in time be made, causes of contention be done
away, and the sources of social misery be dried up, so that——"
"So that we may, through all present dismay and vicissitude, look
forward to ultimate peace on earth and good-will towards men. Yes,
all things are of use to some, from the stalk of flax that waves in my
field below, to Orion now showing himself as the black cloud draws
off,—all for purposes of support to body or mind,—all, whether
appropriated, or left at large because they cannot be appropriated.
Let us hope that each will, at length, have his share; and as
Providence has placed no limit to the enjoyment of his gifts but that
of food, we may learn so to understand one another’s desires as
mutually to satisfy them; so that there may not be too much of one
thing to the injury of some, and too little of another thing, to the
deprivation of more."
“If we could but calculate the present uses of any one gift!” said
Dr. Sneyd, smiling; “but this is a task for the philosophers of another
age, or another state. I would fain know how many living beings are
reposing or pasturing on your flax-stalk, and how much service will
be rendered in the course of the processes it has to go through. I
would fain know how many besides ourselves are drawing from
yonder constellation knowledge and pleasure.”
“More than there are stars in the heaven, besides the myriads that
have their home in one or other of its worlds. What more knowledge
are we to derive to-night?”
And Arthur returned to his seat and his task, which he had quitted
while the sky was clouded. His father observed, with surprise, how
far the twinkling lights had travelled from their former place.
“It is later than I thought, Arthur,” said he. “I ought not to have
kept you so long from your rest, busy as your days are.”
Arthur was quite disposed to go on, till sunrise, if his father
wished to take advantage of his services. He must meet his men
very early in the dewy morning to mow, and the night was now so
far advanced that it would be as well to watch it out. Dr. Sneyd was
very thankful for his aid. When they had satisfied themselves that
the household were gone to rest, and had replenished the lamp,
nothing but brief directions and the ticking of the watch was again
heard in this upper chamber till the chirping of birds summoned the
mower to fetch his scythe.
Chapter V.

INTRODUCTIONS.

The true cause of Mr. Temple’s Sunday headache was spleen at


the occurrence of the morning. That Dr. Sneyd should preach, and in
a market-house, and that soldiers should come some miles to hear
him was, he declared, a perfect scandal to the settlement. He could
not countenance it.
The scandal continued, without the countenance of the scrupulous
gentleman, till the autumn, when the reason of certain magnificent
doings at Temple Hall began to be apparent. Probably the only
persons who could have told what all this new building meant were
forbidden to do so, as Mrs. Sneyd could never obtain a word from
her daughter in return for all her conjectures about what the Lodge
was to grow into at last, the builders having no sooner done one
task than they had to set about another. There was infinite hurry
and bustle about these last additions. Workmen were brought from a
distance to relieve those on the spot, that no part of the long
summer days might be lost. Wall rose above wall; beam followed
beam from the forest, and planks issued from the sawpit with
marvellous speed. One would have thought the President was
expected on a visit before winter; and, in fact, a rumour was current
in the village that some new capitalists were coming to look about
them, and were to be tempted to abide on some of the great man’s
lands. This seemed the more probable as a substantial house was
being built in the Lodge grounds, besides the new wing (as it
appeared to be) of the mansion itself. Every body agreed that this
house must be intended for somebody.
The truth burst forth, one day late in the autumn, that seats
instead of partitions were being put up in the new building, and that
the windows were to be unlike those of the rest of the house:—in
short, that it was to be a chapel. The servants spread abroad the
fact that company was expected in a few days; to stay, they
believed, all the winter.—Ay! till the new house should be ready,
every body supposed. Meantime, Mrs. Temple said nothing more to
her family than that friends of Mr. Temple’s were shortly coming to
stay at the Lodge. She had never seen them, and knew but little
about them:—hoped they might prove an acquisition to her father:—
depended upon Arthur’s civilities, if he should have it in his power,—
and so forth.
It was seldom that Mr. Temple called on his father-in-law,—
especially in the middle of the day, when less irksome things could
be found to do; but, one bright noon, he was perceived approaching
the house, driving the barouche, in which were seated two ladies
and a gentleman, besides the heir of Temple Lodge. Dr. Sneyd
stepped out of his low window into the garden, and met them near
the gate, where he was introduced to the Rev. Ralph Hesselden,
pastor of Briery Creek, and Mrs. Hesselden.
The picturesque clergyman and his showy lady testified all
outward respect to the venerable old man before them. They forgot
for a moment what they had been told of his politics being "sad,
very sad; quite deplorable,"—and remembered only that he was the
father of their hostess. It was not till a full half hour after that they
became duly shocked at a man of his powers having been given over
to the delusions of human reason, and at his profaneness in having
dared to set up for a guide to others while he was himself blinded in
the darkness of error. There was so little that told of delusion in the
calm simplicity of the doctor’s countenance, and something so unlike
profaneness and presumption in his mild and serious manners, that
it was not surprising that his guests were so long in discovering the
evil that was in him.
Mrs. Sneyd was busy about a task into which she put no small
share of her energies. She had heard that nothing that could be
eaten was half so good as pomegranate preserve, well made. In
concert with Arthur, she had grown pomegranates with great
success, and she was this morning engaged in preserving them;
using her utmost skill, in the hope that if it should prove an
impossible thing to make her husband care for one preserve rather
than another while he was in health, this might be an acceptable
refreshment in case of sickness; or that, at least, Temmy would
relish the luxury; and possibly Temple himself be soothed by it in
one of the fits of spleen with which he was apt to cloud the morning
meal.—The mess was stewing, and the lady sipping and stirring,
when her husband came to tell her who had arrived, and to request
her to appear;—came instead of sending, to give her the opportunity
of removing all traces of mortification before she entered the room.
"Mr. and Mrs. Who?—a pastor? what, a methodist?—chaplain at
the Lodge, and pastor of Briery Creek?—My dear, this is aimed at
you."
"One can hardly say that, as I only preached because there was
no one else.—I must not stay. You will come directly, my dear."
"I do not see how I can, my dear,"—glancing from her husband to
her stewpan, under a sense of outraged affection with respect to
both of them. “To take one so by surprise! I am sure it was done on
purpose,”
“Then let us carry it off with as little consternation as we can.
Peggy will take your place.”
"And spoil all I have been doing, I know. And my face is so
scorched, I am not fit to be seen.—I’ll tell you what, my dear," she
went on, surrendering her long spoon to Peggy, and whisking off her
apron,—“if I appear now, I will not go and hear this man preach. I
cannot be expected to do that.”
“We will see about that when Sunday comes,” the doctor turned
back to say, as he hastened back to the party who were amusing
themselves with admiring the early drawings of Mrs. Temple, which
hung against the walls of her mother’s parlour. The doctor brought in
with him a literary journal of a later date than any which had arrived
at the Lodge, and no one suspected that he had been ministering to
his wife’s good manners. Mrs. Temple was in pain for what might
follow the introduction.
There was no occasion for her inward tremors, nor for Dr. Sneyd’s
quick glance at his wife over his spectacles. Mrs. Sneyd might be
fully trusted to preserve her husband’s dignity. She instantly
appeared,—so courteous and self-possessed that no one could have
perceived that she had been hurried. The scorched cheeks passed
with the strangers for the ruddy health attendant on a country life,
and they benevolently rejoiced that she seemed likely to have some
time before her yet, in which to retract her heresies, and repent of
all that she had believed and acted upon through life. It was
cheering to think of the safety that might await her, if she should
happily survive the doctor, and come under their immediate
guidance.
The ladies were left to themselves while Temple was grimacing (as
he did in certain states of nervousness) and whipping the shining toe
of his right boot, and the other gentleman making the plunge into
science and literature in which the doctor always led the way when
he could lay hold of a man of education. One shade of
disappointment after another passed over his countenance when he
was met with questions whether one philosopher was not pursuing
his researches into regions whence many had returned infidels,—
with conjectures whether an eminent patriot was not living without
God in the world,—and with doubts whether a venerable
philanthropist might still be confided in, since he had gone hand in
hand in a good work with a man of doubtful seriousness. At last, his
patience seemed to be put to the proof, for his daughter heard him
say,
“Well, sir, as neither you nor I are infidels, nor likely to become so,
suppose we let that matter pass. Our part is with the good tidings of
great deeds doing on the other side of the world. The faith of the
doers is between themselves and their God.”
"But, sir, consider the value of a lost soul—"
“I have so much hope of many souls being saved by every
measure of wise policy and true philanthropy, that I cannot mar my
satisfaction by groundless doubts of the safety of the movers. Let us
take advantage of the permission to judge them by their fruits, and
then, it seems to me, we may make ourselves very easy respecting
them. Can you satisfy me about this new method,—it is of immense
importance,—of grinding lenses——”
Mr. Hesselden could scarcely listen further, so shocked was he with
the doctor’s levity and laxity in being eager about bringing new
worlds within human ken, while there seemed to the pious a doubt
whether the agents of divine wisdom and benignity would be cared
for by him who sent them.—Mr. Hesselden solemnly elevated his
eyebrows, as he looked towards his wife; and the glance took effect.
The lady began inquiring of Mrs. Sneyd respecting the spiritual
affairs of the settlement. She hoped the population had a serious
turn.
“Why, Madam,” replied Mrs. Sneyd, “every thing has so conduced
to sober the minds of our neighbours, that there has been little room
yet for frivolity among us. The circumstances of hardship, of one
kind or another, that led us all from our old homes were very
serious; and it is a serious matter to quit country and family and
friends; and the first casting about for subsistence in a new land is
enough to bring thought into the wildest brain; and now, when we
have gathered many comforts about us, and can thank Providence
with full hearts, we are not at liberty for idleness and levity. I assure
you that Dr. Sneyd has had to enlarge more against anxiety for the
morrow than against carelessness or vain-glory.”
“I rejoice to hear it. This is good as far as it goes. But I was
inquiring about more important affairs.”
"In more important matters still, I hope you will find much that is
encouraging. We are naturally free from the vices of extreme wealth
or poverty. Among the few whose labours have proved fruitful, there
is a sobriety of manners which I think will please you; and none are
so poor as to be tempted to dishonesty, or driven into recklessness.
The cry of ‘stop thief’ has never been heard in Briery Creek, and you
will neither meet a drunken man nor a damsel dressed in tawdry
finery.—By the way, Louisa," she continued, addressing her daughter,
“I am sorry there is any difficulty about Rundell’s getting more land,
and Chapman’s setting up a general store. I have some fears that as
our neighbours’ earnings increase, we may see them spent in idle
luxuries, unless there is a facility in making a profitable investment.”
“Where is the difficulty, ma’am?” asked Mrs. Temple. “If Rundell
wants land, I rather think Mr. Temple has plenty for him.”
“I understand not.”
Mrs. Temple was about to argue the matter on the ground of her
husband’s thousands of uncultivated acres, but recollecting that
there might be more in the matter than was apparent to her, she
stopped short, and there was a pause.—At length, Mrs. Hesselden,
turning the fullest aspect of her enormous white chip bonnet on Mrs.
Sneyd, supposed that as the neighbourhood was so very moral,
there were no public amusements in Briery Creek.
“I am sorry to say there are none at present. Dr. Sneyd and my
son begin, next week, a humble attempt at a place of evening
resort; and now that Mr. Hesselden will be here to assist them, I
hope our people will soon be provided with a sufficiency of harmless
amusement.”
"You begin next week?—A prayer meeting?" asked the lady,
turning to Mrs. Temple. Mrs. Temple believed not.
“We have our meetings for intercourse on the subjects you refer
to,” replied Mrs. Sneyd; “but I understood you to be inquiring about
places of amusement. My son presented the settlement with a
cricket ground lately.”
“A cricket ground, was it?” said Mrs. Temple. “I thought it had
been a bleaching ground. I understood it was the ladies of the place
who were to be the better for his bounty.”
"That is true also. The same ground serves the washers on the
Monday morning, and the cricketers on the Saturday afternoon. You
must know, Mrs Hesselden, there is much trouble here in getting
soap enough,—and also candles,—for the purposes of all. There is
some objection, I find, to a general store being set up; so that only
the richer of our neighbours can obtain a regular supply of certain
necessary articles; and the poorer ones are just those who find it
most expensive and troublesome to make all the soap and candles
they want. My son, knowing how much consumption is saved by
association, as he says, had a view to these poorer settlers in
opening the bleaching ground. They are truly glad to get their linen
washed twice as well in the field as at home, and at half the
expense of soap. They are very willing to clear the place for the
cricketers three afternoons in the week; and are already beginning
to pay off the cost incurred for the shed, with the boilers and
troughs. I really hardly know which is the prettiest sight,—the games
of the active young men, when they forget the worldly calculations
which are apt to engross new settlers too much,—or the merry
maidens in the field at noon, spreading out linen and blankets of a
whiteness that would be envied by most of the professional
laundresses that I have known."
“All these things,” observed Mrs. Hesselden, "are of inferior
consequence. I mean——"
"Very true: I mention them chiefly as signs of the times—not as
the limit to which our improvements have extended. We are anxious
to provide a reading-room for the youths, at the same time that we
open our school. My daughter has no doubt told you about the
school which she is helping to form. We find that the newspapers
and journals which were always deposited in the cricket-ground
were so much relished by the players in the intervals of their games,
that Dr. Sneyd and my son have determined to light up and warm
the school-house every evening during the winter, to be the resort of
all who choose to go. Dr. Sneyd carries there the humble beginning
of a museum of natural history, which it must be the care of our
neighbours to improve. They can easily do so by exchanging the
productions of our forest and prairie for what may be obtained from
the societies Dr. Sneyd is connected with in England and France. All
the publications sent to us will find their way to the school-house;
and when the snow comes to enable a sleigh to bring us the
packages of glass we have been waiting for these eight months, the
doctor will erect his large telescope, and send an inferior one down
to the village for the use of his star-gazing neighbours."
Observing Mrs. Hesselden’s supercilious silence, Mrs. Sneyd
proceeded, smiling,
"I have had my share in the ordering of the affair, and have
carried two points, nem. con. The women are allowed as free
ingress as their husbands and brothers. I mentioned that candles
were scarce, and you do not need to be told that much sewing must
be done in our households. By bringing their work to the school-
house, (which is within a stone’s throw of most of the doors,) many
of our hard-working mothers and daughters will be spared the
trouble and expense of making above half as many candles as if
each must have one burning during the whole of the long evenings
of winter. What is more important,—they will share the benefit of the
reading and other amusements that may be going on. My other
point is the dancing. I told Dr. Sneyd that if he carried a telescope,
and made them chill themselves with star-gazing, I must beg leave
to carry a fiddle for them to warm their feet by when they had done.
Two fiddlers have turned up already, and there are rumours of a
flute-player; and I have half promised my grandchild to lead off the
first dance, if he will persuade my son to take me for a partner."
Mrs. Hesselden hoped that others would also be allowed to carry
their points, and then there would be prayer on meeting and parting
in the school-house. If it should be found that such an exercise was
incompatible with the dancing part of the scheme, she trusted Mrs.
Sneyd saw which must give way.
Mrs. Sneyd would advocate no practice which was incompatible
with religious duty. In the present case, she thought that the only
concession required was that each exercise should have its proper
season. None of the usual objections to dancing would hold good
here, she continued. No shivering wretches stood without, while the
rich were making merry. There was no inducement to extravagance,
and no room for imprudence, and no encouragement to idleness.
There was no scope for these vices among the working-class of
Briery Creek, and dancing was to them (what it would be in many
another place, if permitted) an innocent enjoyment, a preventive of
much solitary self-indulgence, and a sweetener of many tempers. In
a society whose great danger was the growth of a binding spirit of
worldliness, social mirth was an antidote which no moralist would
condemn, and which he would not dare to despise.
Mrs. Hesselden, fearing that she could never make Mrs. Sneyd
comprehend how much more she and her husband were than mere
moralists, quitted the subject till she could explain to Mrs. Temple on
the way home, that though the presence of the Sneyds had
undoubtedly been of great use in fostering a morality which was
better than nothing, yet it was evidently high time that more should
be added, and certainly a great blessing to Briery Creek that her
husband and she had arrived to breathe inspiration into the social
mass which was now lying,—if not dead,—yet under the shadow of
death.
Mrs. Sneyd found time, before returning to her pomegranates, to
take a last wondering look at the immensity of Mrs. Hesselden’s chip
bonnet, as it floated, splendid in its variegated trimming, over the
shrubs in her passage to the garden gate.
“I can never make out,” she observed to her husband, "why so
many of these very strict religious people dress so luxuriously as
they do. Here is this lady,—infinitely scandalized, I perceive, at our
having introduced dancing,—dressed after such a fashion as our
maidens never saw before. If they begin to bedizen themselves with
the money which might be spent profitably in increasing the means
of subsistence, or innocently in procuring substantial comforts which
are now difficult to be had, I shall lay the blame on Mrs. Hesselden’s
bonnet. I remember observing that I never saw so splendid a show-
room for dress as the new church we attended, in ——- street, the
Sunday before we left London. It is very odd."
"Not more strange, my dear, than that the Friends should addict
themselves much to the furnishing their houses with expensive
furniture, and their tables with more costly and various foods than
other people. Not more strange than that Martin, the Methodist,
should turn strolling player when he gave up his methodism; or that
the Irish betake themselves to rebellion when stopped in their
merry-makings; or that the English artizan takes to the gin-shop
when the fiddle is prohibited in the public-house. Not more strange,
my dear, than that the steam of your kettle should come out at the
lid, if you stop up the spout, or than that——"
“O, you put me in mind of my preserves! But how did you think
Louisa looked to-day?”
"Not very well. There was a something—I do not know what——"
"Well, I wondered whether you would observe. It may be the
contrast of Mrs. Hesselden’s dress that made me remark the thing so
much. It really vexed me to see Louisa so dressed. That collar was
darned like any stocking-heel; and how she got her bonnet ribbons
dyed in this place, I cannot think. What can be the meaning of her
being so shabby? It is so contrary to her taste,—unless she has
taken up a new taste, for want of something to do."
Dr. Sneyd shook his head. He knew that Temple left his lady no
lack of something to do. Temmy had also dropped a piece of
information about wax candles lately, which convinced the doctor
that the lady at the Hall was now compelled to economize to the last
degree in her own expenditure, whatever indulgence might still be
afforded to her tyrant’s tastes.
“He looks wretchedly too,” observed Mrs. Sneyd. “Not all his
spruceness could hide it, if he was as spruce as ever. But there is a
change in him too. One might almost call his ensemble slovenly to-
day, though it would be neatness itself in many another man. I
believe he half kills himself with snuff. He did nothing but open and
shut his box to-day. So much snuff must be very bad for a nervous
man like him.”
“Do you know, my dear,” said the doctor, "I have been thinking
lately whether we are not all rather hard upon that poor man——
Yes, yes, I know. I am not going to defend, only to excuse him a
little. I am as unhappy as you can be about all that Louisa has to go
through with him, and about his spoiling that poor boy for life,—
doing all that can be done to make him a dolt. But I am sure the
man suffers—suffers dreadfully."
“Suffers! How?”
"Nay, you need but look in his face to see whether he is a happy
man or not; but what his ailments are, I do not pretend to say. His
nerves torture him, I am certain——"
Mrs. Sneyd insinuated speculations about indulgence in brandy,
opium, spices, &c., and about remorse, fear, and the whole demon
band of the passions. Dr. Sneyd’s conjecture was that Temple’s
affairs were in an unsatisfactory condition, and that this trouble,
acting on the mind of a coward, probably drove him to the use of
sufficient stimulus to irritate instead of relieving him. Great
allowance, he insisted, should be made for a man in so pitiable a
state, even by the parents of his wife. This was so effectually
admitted by the good lady, that she not only sent a double portion of
pomegranate preserve to the Lodge, but restrained her anger when
she heard that Rundell could not obtain liberty to invest as he
pleased the capital he had saved, owing to Temple’s evil influence at
the land-office; and that Arthur’s interests were wantonly injured by
his interference. Arthur had taken great pains to secure a supply of
fresh meat and fresh butter for the approaching winter; and besides
the hope of profit from his fine sheep and cows, he had the
assurance of the gratitude of his neighbours, who had grown heartily
weary of salt pork and salt butter the winter before. But Mr. Temple
now set up a grand salting establishment; and made it generally
understood that only those who were prudent enough to furnish
themselves with his cheap salt provision, rather than Mr. Sneyd’s
dear mutton, should have his custom in the market, and his
countenance at the land-office. Arthur’s first-slain sheep had to be
eaten up by his father’s household and his own; and it was a piece
of great forbearance in Mrs. Sneyd, when she heard that Arthur
meant to kill no more mutton, to say only, “The poor little man
punishes nobody so much as himself. I do not see how he can relish
his own fresh mutton very much, while he prevents other people
having any.”
“He cannot altogether prevent that, mother,” said Arthur. "He may
prevent mutton bearing any price in the market, and cut off my
gains; but we may still slay a sheep now and then, for ourselves;
and find neighbours who will quietly make such an exchange of
presents as will take off what we cannot consume. But I wish I could
see an end of this dictation,—this tyranny."
“It does seem rather strange to have come to a land of freedom to
be in the power of such a despot. I wonder the people do not shake
him off, and send him to play the tyrant farther in the wilds.”
“They are only waiting till his substance is all consumed, I fancy.
He has such a hold over the investments of some, and finds so much
employment for the labour of others, that they will submit to
everything for a time. But his hour will come, if he does not beware.”
“It may be all very well for those who have investments to take
time to extricate their capital from his grasp,” said Mrs. Sneyd; “but
as for the builders and gardeners he employs, I think they would be
wiser if they carried their labour where they might depend on a
more lasting demand for it. Anybody may see that if he spends more
every year in undoing what he did the year before, his substance
must soon come to an end, and his labourers become his creditors.
If I were they, I would rather go and build barns that are paid for by
the preservation of the corn that is in them, and till fields that will
maintain the labour of tillage, and set more to work next year, than
turn round a fine house from south to west, and from west to south,
and change shrubberies into lawns, and lawns into flower-gardens,
knowing that such waste must come to an end.”
“But some do not believe that it is waste, mother. They see the
money that pays them still in existence, still going the round of the
market; and they talk (as some people in England do about royal
palaces, and spendthrift noblemen’s establishments) of the blessing
of a liberal expenditure, and the patriotism of employing so much
labour.”
"Which would be all very well if the labourers lived upon the sight
of the money they are paid with. But, as long as that money is
changed many times over for bread and clothing, which all
disappears in the process, it is difficult to make out that anything is
gained but the pleasure,—which may be justifiable or not, according
to the circumstances of the employers. In the end, the money
remains as it was before, and instead of so much food and clothing,
there is a royal palace. If you do not like your palace, and pull it
down and rebuild it, the money exists as before, and for a double
quantity of food and clothing, you still have a palace."
“The wrong notion you speak of arises partly,” said Dr. Sneyd,
“from a confusion between one sort of unproductive expenditure and
another. People hear of its being a fine thing to employ a crowd of
labourers in making a new line of road, or building a bridge, and
they immediately suppose it must be a patriotic thing to employ a
crowd of labourers in building any thing.”
“I think they might perceive that, though corn does not grow on a
high road, nor bridges yield manufactures, the value of corn lands
may be doubled by opening a way to a new market, and that an
unused water power may begin to yield wealth from the moment
that there is a bridge over which buyers may come for it. It is a
misfortune to Briery Creek that Temple is more of a selfish palace-
fancier than a patriotic bridge and road maker.”
The first Sunday of the opening of the chapel, Temple appeared in
a character which he had only once before attempted to support. On
the occasion of using the market-house for service, he had
approached the door, cast a glance within upon the company of
soldiers, and the village population at their worship, while their aged
friend was leading their devotions, and hastily departed, thankful
that he was too pious to join in such a service as this. He took the
part of a religious man that day, and now was the time for him to
resume the character. Under the idea that the market-house might
be opened as usual for Dr. Sneyd, making his own appear like an
opposition place of worship, he spared no pains to secure a majority
in point of audience. He had managed to ride past the military post,
and be gracious with the soldiers. His domestics puffed the chapel
and chaplain at market, the day before, and the leading villagers
received intimations of good sittings being appropriated to them.
These pains might have been spared. All who desired might know
that Dr. Sneyd, his wife, son, and servants intended to be present,
as a matter of course.
When they entered, Temple looked nearly as much surprised as if
they had at the moment arrived from England. He made a
prodigious bustle about having them accommodated in a seat next
his own, and condescendingly sent them books, and inquired into
the sufficiency of hassocks. During the greater part of the service he
stood up, as if he could not listen with sufficient attention while
sitting, like other people. Yet he cleared his throat if any body
moved, and sent his pert glance into every corner to command a
reverential demeanour, while his chaplain was enforcing, as the
prime glory and charm of a place of worship, that there, and there
alone, all are equal and all are free. Little Ephraim cowered behind
the coachman while the preacher insisted that here the humblest
slave might stand erect on the ground of his humanity; and the
butler stepped on tiptoe half way down the aisle to huff Jenkins the
ditcher for coming so high up, at the very moment that something
was quoted about a gold ring and purple raiment in the synagogue.
It was true the preacher and his message had not so good a
chance of being attended to as they might have on future Sundays.
The bustle produced by the anticipation of the occasion did not
subside on the arrival of the occasion. The fine large chip bonnets
had been procured, and the trimming and sending them home had
been achieved by the Saturday night. But it remained to wear them
for the first time: not only to support the consciousness of a new
piece of finery, but to compare the fine bonnets with the shabby
head-gear of other people, with each other, and, finally, with Mrs.
Hesselden’s. Then, while Mrs. Dods was thus contemplating the
effect of her own peculiar species of architecture, her husband could
not but look round him, and remember that every individual brick of
this pile had been fashioned by himself and his lads. The builder
scanned the measurements of the windows and the ceiling. Two or
three boys and girls shuffled their feet on the matting which their
mother had woven. A trader from the north gradually made up his
mind to approach the ladies after service, for the purpose of
recommending fur pouches for the feet during the severe season
that was approaching. The Brawnees, unincumbered by any thing
beyond their working-day apparel, were among the best listeners.
Temmy was so alarmed at the prospect of having to give his father,
for the first time, an account of the sermon, that he could not have
taken in a word of it, even if he had not been miserable at seeing
the tears coursing one another down his mother’s cheeks during the
whole time of the service. Her left hand hung by her side, but he did
not dare to touch it. He looked at Mrs. Hesselden to try to find out
whether she thought his mother was ill; or whether the sermon was
affecting; or whether this was the consequence of something that
had been said at breakfast against grandpapa. Grandpapa seemed
to be listening very serenely to the sermon, and that was a better
comfort than Mrs. Hesselden’s countenance,—so grave, that Temmy
feared to provoke a cross word if he looked at her again.
It was not known, till the ladies of the village ranged themselves
round the work-table in the school-house, one chilly evening, soon
afterwards, how great had been the bustle of preparation before the
fine chip bonnets made their appearance in the chapel. All hearts,
even those of rival milliners, were laid open by the sight of the
roaring wood fire, the superior candles, the hearty welcome, and the
smiling company that awaited them as they dropped in at the place
of entertainment,—the women with their sewing apparatus, and
their husbands and brothers ready for whatever occupation might
have been devised for their leisure evening hours. While these latter
crowded round the little library, to see of what it consisted, the
sewers placed their benches round the deal table, snuffed their
candles, and opened their bundles of work. Mrs. Dods made no
mystery of her task. She was cutting up a large chip bonnet to make
two small hats for her youngest boy and girl, owning that, not
having calculated on any one else attempting to gratify the rage for
imitating Mrs. Hesselden, she had injured her speculation by
overstocking the market. The lawyer’s lady had been reckoned upon
as a certain customer; but it turned out,—however true that the
lawyer’s lady must have a chip bonnet,—that the builder’s wife had
just then entered upon a rivalship with the brickmaker’s wife, and
had stuck up at her window bonnets a trifle cheaper than those of
Mrs. Dods. It only remained for Mrs. Dods to show how pretty her
little folks looked in hats of the fashionable material, in hopes that
the demand might spread to children.
“If it does, Mrs. Dods, Martha Jenkins will have the same reason
to complain of you that you have to complain of being interfered
with. It is unknown the trouble that Jenkins has had, following the
river till he came to the beavers, and then hunting them, and
preparing their skins at home, and all that, while Martha spared no
pains to make beaver hats for all the boys and girls in the place. It
will be rather hard if you cut her out.”
“And you can do it only by lowering your price ruinously,” observed
Mrs. Sneyd. “I should think any mother in Briery Creek would rather
keep her child’s ears from freezing by putting on her a warm beaver,
than dress her out prettily in a light chip, at this season. Nothing but
a great difference in price can give yours the preference, I should
think, Mrs. Dods.”
“Then such a difference there must be,” Mrs. Dods replied. “I had
rather sell my article cheap than not sell it at all. Another time I shall
take care how I run myself out at elbows in providing for a new
fashion among the ladies.”
Mrs. Sneyd thought that those were engaged in the safest traffic
who dealt in articles in the commonest use,—who looked for custom
chiefly from the lower, i.e. the larger classes of the people. From
their numbers, those classes are always the greatest consumers;
and, from the regularity of their productive industry, they are also
the most regular consumers. It seemed probable that the demand
for Martha Jenkins’s beavers would prove superior in the long run to
that for Mrs. Dods’s varied supply, though poor Martha might suffer
for a while from the glut of chips which occasioned loss to all sellers
of bonnets, at present, and gain to all sellers of whatever was given
in exchange for bonnets. Fat for candles was scarcely to be had
since Temple had discouraged the sale of fresh meat. Mrs. Dods was
deplorably in want of candles. She made a bargain with a neighbour
for some in return for the hat now under her hands. How few she
was to receive, it vexed her to think; but there was no help for it till
somebody should supply the deficiency of candles, or till new heads
should crave covering.
It now appeared that the ladies were not the only persons who
had brought their work. When it came to be decided who should be
the reader, it was unanimously agreed that some one who had no
employment for his hands should undertake the office. Dods had
leathern mittens to make for the less hardy of the woodsmen.
Others occupied themselves in platting straw, making mops, cutting
pegs to be employed in roofing, and cobbling shoes. Arthur drew
sketches for Temmy to copy. Such was always the pretence for
Arthur’s drawings; but a neighbour who cast a peep over his
shoulder, from time to time, could not help thinking that the sketch
was of the present party, with Dr. Sneyd in the seat of honour by the
fire-side, Mrs. Sneyd knitting in the shadow, that the full benefit of
the candles might be yielded to those whose occupation required it;
Isaac, who had received the honour of the first appointment as
reader, holding his book rather primly, and pitching his voice in a key

You might also like