Beginning XML with C# 7: XML Processing and Data Access for C# Developers 2nd Edition Bipin Joshi (Auth.) 2024 scribd download
Beginning XML with C# 7: XML Processing and Data Access for C# Developers 2nd Edition Bipin Joshi (Auth.) 2024 scribd download
com
https://textbookfull.com/product/beginning-xml-with-c-7-xml-
processing-and-data-access-for-c-developers-2nd-edition-
bipin-joshi-auth/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/c-and-xml-primer-1st-edition-
jonathan-hartwell-auth/
textboxfull.com
https://textbookfull.com/product/java-xml-and-json-document-
processing-for-java-se-2nd-edition-jeff-friesen/
textboxfull.com
https://textbookfull.com/product/java-xml-and-json-document-
processing-for-java-se-jeff-friesen/
textboxfull.com
https://textbookfull.com/product/java-xml-and-json-friesen-jeff/
textboxfull.com
Beginning C 7 Programming with Visual Studio 2017 1st
Edition Benjamin Perkins
https://textbookfull.com/product/beginning-c-7-programming-with-
visual-studio-2017-1st-edition-benjamin-perkins/
textboxfull.com
https://textbookfull.com/product/beginning-c-7-hands-on-the-core-
language-tom-owsiak/
textboxfull.com
https://textbookfull.com/product/pro-restful-apis-design-build-and-
integrate-with-rest-json-xml-and-jax-rs-patni/
textboxfull.com
https://textbookfull.com/product/data-structures-with-c-
programming-2nd-edition-anil-kumar-yadav/
textboxfull.com
Beginning
XML with C# 7
XML Processing and Data Access for
C# Developers
—
Second Edition
—
Bipin Joshi
Beginning XML with C# 7
XML Processing and
Data Access for C# Developers
Second Edition
Bipin Joshi
Beginning XML with C# 7: XML Processing and Data Access for C# Developers
Bipin Joshi
301 Pitruchhaya, Thane, India
ISBN-13 (pbk): 978-1-4842-3104-3 ISBN-13 (electronic): 978-1-4842-3105-0
https://doi.org/10.1007/978-1-4842-3105-0
Library of Congress Control Number: 2017961825
Copyright © 2017 by Bipin Joshi
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Cover image by Freepik (www.freepik.com)
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Technical Reviewer: Michael Thomas
Coordinating Editor: Mark Powers
Copy Editor: Kezia Endsley
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring
Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC
and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail rights@apress.com, or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions
and licenses are also available for most titles. For more information, reference our Print and eBook Bulk
Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book's product page, located at www.apress.com/9781484231043. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
This work is dedicated to Lord Shiva, who, I believe,
resides in each one of us as pure consciousness.
Contents
■
■Chapter 1: Introducing XML and the .NET Framework������������������������������������������ 1
What Is XML?������������������������������������������������������������������������������������������������������������������� 1
Benefits of XML�������������������������������������������������������������������������������������������������������������������������������������� 2
XML-Driven Applications������������������������������������������������������������������������������������������������������������������������ 3
v
■ Contents
ADO.NET������������������������������������������������������������������������������������������������������������������������������������������������ 17
ASP.NET Web Forms Server Controls���������������������������������������������������������������������������������������������������� 17
XML Serialization���������������������������������������������������������������������������������������������������������������������������������� 18
Web Services, WCF Services, and Web API������������������������������������������������������������������������������������������� 19
XML Documentation����������������������������������������������������������������������������������������������������������������������������� 19
XAML Markup��������������������������������������������������������������������������������������������������������������������������������������� 21
SQL Server XML Features��������������������������������������������������������������������������������������������������������������������� 21
Summary������������������������������������������������������������������������������������������������������������������������ 28
■
■Chapter 2: Manipulating XML Documents Using the Document Object Model����� 29
Using the DOM Parser���������������������������������������������������������������������������������������������������� 29
Knowing When to Use DOM�������������������������������������������������������������������������������������������� 31
A Sample XML Document����������������������������������������������������������������������������������������������� 32
Opening an Existing XML Document for Parsing������������������������������������������������������������ 33
Navigating Through an XML Document�������������������������������������������������������������������������� 35
Looking for Specific Elements and Nodes���������������������������������������������������������������������� 36
Retrieving Specific Elements Using the GetElementsByTagName() Method���������������������������������������� 37
Retrieving Specific Elements Using the GetElementById() Method������������������������������������������������������ 38
Selecting Specific Nodes Using the SelectNodes() Method������������������������������������������������������������������ 41
Selecting a Single Specific Node Using the SelectSingleNode() Method��������������������������������������������� 43
vi
■ Contents
vii
■ Contents
Summary������������������������������������������������������������������������������������������������������������������������ 84
■
■Chapter 4: Accessing XML Documents Using the XPath Data Model������������������� 85
Overview of XPath���������������������������������������������������������������������������������������������������������� 85
Location Path���������������������������������������������������������������������������������������������������������������������������������������� 86
Axis������������������������������������������������������������������������������������������������������������������������������������������������������� 86
Node Tests�������������������������������������������������������������������������������������������������������������������������������������������� 86
Predicates��������������������������������������������������������������������������������������������������������������������������������������������� 87
Putting It All Together��������������������������������������������������������������������������������������������������������������������������� 87
XPath Functions������������������������������������������������������������������������������������������������������������������������������������ 87
Summary���������������������������������������������������������������������������������������������������������������������� 109
■
■Chapter 5: Validating XML Documents�������������������������������������������������������������� 111
Providing Structure for XML Documents���������������������������������������������������������������������� 111
Document Type Definition (DTD)��������������������������������������������������������������������������������������������������������� 112
XML Data Reduced (XDR) Schema������������������������������������������������������������������������������������������������������ 112
XML Schema Definition (XSD) Schema����������������������������������������������������������������������������������������������� 112
viii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 173
ix
■ Contents
■
■Chapter 7: XML in ADO.NET������������������������������������������������������������������������������� 175
Overview of ADO.NET Architecture������������������������������������������������������������������������������� 175
Connected Data Access���������������������������������������������������������������������������������������������������������������������� 175
Disconnected Data Access����������������������������������������������������������������������������������������������������������������� 176
ADO.NET Data Providers��������������������������������������������������������������������������������������������������������������������� 177
ADO.NET Classes�������������������������������������������������������������������������������������������������������������������������������� 178
Summary���������������������������������������������������������������������������������������������������������������������� 210
■
■Chapter 8: XML Serialization����������������������������������������������������������������������������� 211
Understanding the Flavors of Serialization������������������������������������������������������������������ 211
Classes Involved in the XML Serialization������������������������������������������������������������������������������������������ 212
x
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 237
■
■Chapter 9: XML in Web Services������������������������������������������������������������������������ 239
What Are Web Services?���������������������������������������������������������������������������������������������� 239
Creating and Consuming Web Services����������������������������������������������������������������������� 240
Creating a Web Service���������������������������������������������������������������������������������������������������������������������� 241
Creating a Proxy for a Web Service���������������������������������������������������������������������������������������������������� 254
Creating a Form That Calls the Web Methods������������������������������������������������������������������������������������� 256
Summary���������������������������������������������������������������������������������������������������������������������� 267
■
■Chapter 10: XML in WCF and Web API��������������������������������������������������������������� 269
Operations Based Services vs. Resource Based Services������������������������������������������� 270
Understanding WCF Vocabulary����������������������������������������������������������������������������������� 270
Creating and Consuming a WCF Service���������������������������������������������������������������������� 271
Creating the Service��������������������������������������������������������������������������������������������������������������������������� 271
Hosting the Service���������������������������������������������������������������������������������������������������������������������������� 276
Consuming the Service����������������������������������������������������������������������������������������������������������������������� 279
Testing the Host and Client����������������������������������������������������������������������������������������������������������������� 282
xi
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 304
■
■Chapter 11: XML in SQL Server�������������������������������������������������������������������������� 305
Using XML Extensions to the SELECT Statement��������������������������������������������������������� 305
The FOR XML Clause�������������������������������������������������������������������������������������������������������������������������� 305
Summary���������������������������������������������������������������������������������������������������������������������� 333
■
■Chapter 12: XML in .NET Framework����������������������������������������������������������������� 335
Using XAML to Define the WPF User Interface������������������������������������������������������������� 335
Displaying XML Data in a WPF Application������������������������������������������������������������������� 340
Using XML in ASP.NET�������������������������������������������������������������������������������������������������� 342
XML and ASP.NET�������������������������������������������������������������������������������������������������������������������������������� 343
The XML Data Source Control������������������������������������������������������������������������������������������������������������� 351
xii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 385
■
■Chapter 13: Working with LINQ to XML������������������������������������������������������������� 387
Overview of LINQ���������������������������������������������������������������������������������������������������������� 387
Working with LINQ Queries����������������������������������������������������������������������������������������������������������������� 388
xiii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 419
■
■Appendix A: Creating a Custom XmlReader and XmlWriter������������������������������ 421
Creating a Custom XmlReader������������������������������������������������������������������������������������� 421
Inheriting from XmlReader����������������������������������������������������������������������������������������������������������������� 422
Creating the TableReader Class���������������������������������������������������������������������������������������������������������� 423
Using the TableReader Class�������������������������������������������������������������������������������������������������������������� 431
xiv
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 442
■
■Appendix B: Resources�������������������������������������������������������������������������������������� 443
W3C Web Site for XML Specifications�������������������������������������������������������������������������� 443
W3C Web Site for XML Schema Specifications������������������������������������������������������������ 443
W3C Web Site for XPath-Related Information�������������������������������������������������������������� 443
W3C Web Site for XSL-Related Information������������������������������������������������������������������ 443
W3C Web Site for SOAP Specifications������������������������������������������������������������������������ 443
System.Xml Reference������������������������������������������������������������������������������������������������� 443
.NET/ASP.NET/WCF/Web API����������������������������������������������������������������������������������������� 444
Wikipedia—XML Section��������������������������������������������������������������������������������������������� 444
Author’s Web Site on .NET and Web Development������������������������������������������������������� 444
XML Notepad—XML Editor������������������������������������������������������������������������������������������ 444
Sandcastle Help File Builder���������������������������������������������������������������������������������������� 444
SQLXML Programming������������������������������������������������������������������������������������������������� 444
Index��������������������������������������������������������������������������������������������������������������������� 445
xv
About the Author
Bipin Joshi is a software consultant, trainer, author, and yoga mentor who writes about seemingly unrelated
topics: software development and yoga! He conducts online training courses to help developers learn
ASP.NET and web technologies better and faster. Currently his focus is ASP.NET, ASP.NET Core, C#,
JavaScript frameworks, and design/architectural patterns. More details about his training courses are
available at http://www.binaryintellect.com.
Bipin has been programming since 1995 and has worked with the .NET Framework since its inception.
He is a published author and has authored or co-authored more than 10 books and numerous articles on
.NET technologies. He regularly writes about ASP.NET and other cutting-edge web technologies on his web
site at http://www.binaryintellect.net. Bipin is a Microsoft Most Valuable Professional (MVP) and a
former Microsoft Certified Trainer (MCT).
Having embraced the yoga way of life, he enjoys the intoxicating presence of God and writes about yoga
on his web site at http://www.bipinjoshi.org. Bipin has also penned a few books on yoga and teaches
yoga and meditation to selected individuals. He can be reached through his web sites.
xvii
About the Technical Reviewer
xix
Introduction
The Internet has brought a huge difference in the way we develop and use software applications.
Applications have become more complex and distributed, connecting heterogeneous systems.
With such a radical change, the role of XML is highly significant. XML has already established itself as
a standard way of data encoding and transfer. In spite of the popularity of formats such as JSON (JavaScript
Object Notation), XML is still being used in a wide range of applications, including enterprise applications.
XML comes with a family of technologies such as XSLT, XPath, and XSD, that provide a fuller support for
transforming, querying, and validating the underlying data.
No wonder that Microsoft’s .NET Framework provides such a strong support for XML. Data access, raw
parsing, serialization, configuration, code documentation, and services are some of the examples where the
.NET Framework harnesses the power and flexibility of XML.
The .NET Framework comes with a plethora of classes that allow you to work with XML data. This book
demystifies XML and allied technologies. Reading and writing XML data, using DOM, ADO.NET integration
with XML, SQL Server XML features, applying XSLT style sheets, SOAP, use of XML in services (ASMX/
WCF/Web API), and configuration systems are some of the topics that this book explores in detail. Neat
and concise examples scattered throughout the book will help you understand the practical use of the topic
under consideration. The book can also act as a handy reference when developers go on the job.
Software Required
In order to work with the examples presented in this book, you need the following software:
• Visual Studio 2017: I used the Professional Edition of the product but for most of the
examples you can also use the Community Edition.
• .NET Framework 4.7 and C# 7: I used .NET Framework 4.7 to build the examples
discussed in this book. The examples and code fragments are written using C# 7.
• SQL Server with Northwind sample database: In the examples that rely on a
database, I used SQL Server 2012 Developer Edition. You may also use some later
version of the product if you so wish. Throughout the book we use data from the
Northwind sample database. So, you need it ready in the SQL Server. You can
download the required scripts from Microsoft’s official web site.
xxi
■ Introduction
• SQLXML 4.0 SP1: In the examples that discuss SQLXML programming, you need
SQLXML 4.0 SP1 installed on your machine. It can be downloaded from Microsoft’s
official web site.
• Sandcastle Help File Builder (SHFB): In the examples that discuss XML code
commenting, you need SHFB to generate the documentation. You can download it
from its GitHub page.
• Browser: In the examples that require a web browser, I used Firefox. But any other
browser should also work.
xxii
CHAPTER 1
Over the years XML has emerged as one of the most important standards for data representation and
transportation. No wonder that Microsoft has embraced it fully in the .NET Framework. This chapter
provides an overview of what XML is and how it is related to the .NET Framework. Many of the topics
discussed in this chapter might be already familiar to you. Nevertheless, I will cover them briefly here so as
to form a common platform for further chapters. Specifically, this chapter covers the following:
• Features and benefits of XML
• Rules of XML grammar
• Brief introduction to allied technologies such as DTD, XML Schema, parsers, XSLT,
and XPath
• Overview of the .NET Framework
• Use of XML in the .NET Framework
• Introduction to Visual Studio
If you find these concepts highly familiar, you may want to skip ahead to Chapter 2.
What Is XML?
XML stands for Extensible Markup Language and is a markup language used to describe data. It offers a
standardized way to represent textual data. Often the XML data is also referred to as an XML document.
The XML data doesn’t perform anything on its own; to process that data, you need to use a piece of software
called a parser. Unlike Hypertext Markup Language (HTML), which focuses on how to present data, XML
focuses on how to represent data. XML consists of user-defined tags, which means you are free to define and
use your own tags in an XML document.
XML was approved as a recommendation by the World Wide Web Consortium (W3C) in February 1998.
Naturally, this very fact contributed a lot to such a wide acceptance and support for XML in the software
industry.
Now that you have brief idea about XML, let’s see a simple XML document, as illustrated in Listing 1-1.
Many rules govern the creation of such XML documents. But we will save them for later discussion.
Benefits of XML
Why did XML become so popular? Well, this question has many answers, and I will present some of the
important ones in this section.
XML Is Self-Describing
XML documents are self-describing. Because of markup tags, they are more readable than, say, comma-
separated values (CSV) files.
XML Is Extensible
Markup languages such as HTML have a fixed set of tags and attributes—you cannot add your own tags.
XML, on the other hand, allows you to define your own markup tags.
As I said earlier, XML documents can be processed by a piece of software called a parser. Because XML
documents use markup tags, a parser can read them easily. Parsers are discussed in more detail later in this
chapter.
XML-Driven Applications
Now that you know the features and benefits of XML, let’s see what all these benefits mean to modern
software systems.
Figure 1-1 shows a traditional web-based application. The application consists of ASP.NET pages
hosted on a web server. The client, in the form of a web browser, requests various web pages. On receiving
the requests, the web server processes them and sends the response in the form of HTML content. This
architecture sounds good at first glance, but suffers from several shortcomings:
• It considers only web browsers as clients.
• The response from the web server is always in HTML. That means a desktop-based
application may not render this response at all.
• The data and presentation logic are tightly coupled. If we want to change the
presentation of the same data, we need to make considerable changes.
• Tomorrow, if some other application wants to consume the same data, it cannot be
shared easily.
3
Chapter 1 ■ Introducing XML and the .NET Framework
Now, let’s see how XML can come to the rescue in such situations.
■■Note For the sake of easy understanding the example discussed here is deliberately kept very simple and
straightforward. In a more realistic case there could be one or more services involved that return the XML data.
The applications then consume those services as and when required. You will learn how XML and services are
related in later chapters.
Have a look at Figure 1-2, where there are multiple types of clients. One is a web browser, and the other
is a desktop application. Both send requests to the server along with XML data (if any). The server processes
the requests and sends back the data in XML format. The web browser applies a style sheet (discussed later)
to the XML data to transform it into HTML markup. The desktop application, on the other hand, parses the
data by using an XML parser (discussed later) and displays it in a grid. Much more flexible than the previous
architecture, isn’t it? The advantages of the new architecture are as follows:
• The application has multiple types of clients. It is not tied only to web browsers.
• There is loose coupling between the client and the processing logic.
• New types of clients can be added at any time without changing the processing logic
on the server.
• The data and the presentation logic are neatly separated from each other. Web
clients have one set of presentation logic, whereas desktop applications have their
own presentation logic.
• Data sharing becomes easy, because the outputted data is in XML format.
4
Chapter 1 ■ Introducing XML and the .NET Framework
5
Chapter 1 ■ Introducing XML and the .NET Framework
Line 1 is called a processing instruction. A processing instruction is intended to supply some information
to the application that is processing the XML document. Processing instructions are enclosed in a pair of
<? and ?>. The xml processing instruction in Figure 1-3 has two attributes: version and encoding. The W3C
recommendations for XML hold version 1.0, hence the version attribute is set to 1.0.
■■Note You may come across XML 1.1 while reading more about XML specifications. There are minor
differences between XML 1.0 and XML 1.1. However, considering the wide acceptance for version 1.0 most of
the XML documents prefer to mention that version. When you add a new XML file using Visual Studio it has its
version attribute set to 1.0. You can find more details about these differences on the official web site of W3C.
Line 2 represents a comment. A comment can appear anywhere in an XML document after the xml
processing instruction and can span multiple lines.
Line 3 contains the document element of the XML document. An XML document has one and only one
document element. XML documents are like an inverted tree, and the document element is positioned at
the root. Hence, the document element is also called a root element. Each element (whether or not it is the
document element) consists of a start tag and an end tag. The start tag is <customers>, and the end tag is
</customers>.
It is worthwhile to point out the difference between three terms: element, node, and tag. When you say
element, you are essentially talking about the start tag and the end tag of that element together. When you say
tag, you are talking about either the start tag or end tag of the element, depending on the context. When you
say node, you are referring to an element and all its inner content, including child elements and text.
Inside the <customers> element, you have two <customer> nodes. The <customer> element has one
attribute called ID. The attribute value is enclosed in double quotes. The <customer> element has three
child elements: <name>, <email>, and <comments>. The text values inside elements, such as <name> and
<email>, are often called text nodes. Sometimes, the text content that you want to put inside a node may
contain special characters such as < and >. To represent such content, you use a character data (CDATA)
section. Whatever you put inside the CDATA section is treated as a literal string. The <comments> tag shown in
Figure 1-3 illustrates the use of a CDATA section.
Now that you have this background, you’re ready to look at the basic rules of XML grammar. Any XML
document that conforms to the rules mentioned next is called a well-formed document.
6
Chapter 1 ■ Introducing XML and the .NET Framework
text can be written by using shorter notation. For example, assuming that the <customer> tag doesn’t contain
any child elements, you could have written it as <customer ID="C001"/>.
<B><I>Hello World</B></I>
This, however, is illegal in XML, where the nesting of start and end tags must be proper. The correct
representation of the preceding markup in XML would be as follows:
<B><I>Hello World</I></B>
<IMG SRC=myphoto.jpg>
However, this is illegal in XML. All attribute values must be enclosed in quotes. Thus the accepted XML
representation of the preceding markup would be as follows:
7
Chapter 1 ■ Introducing XML and the .NET Framework
DOM-based parsers are read-write parsers, which means you can read as well as write to the XML
document. They allow random access to any particular node of the XML document, and therefore, they need
to load the entire XML document in memory. This also implies that the memory footprint of DOM-based
parsers is large. DOM-based parsers are also called tree-based parsers for obvious reasons.
SAX-based parsers do not read the entire XML document into memory at once. They essentially scan
the document serially from top to bottom. When they encounter various parts of the document, they raise
events, and you can handle these events to read the document. SAX parsers are read-only parsers, which
means you cannot use them to modify an XML document. They are useful when you want to read huge XML
documents and loading such documents into memory is not advisable. These types of parsers are also called
event-based parsers.
8
Chapter 1 ■ Introducing XML and the .NET Framework
Pull-model parsers iterate through an XML document sequentially. They use the iterator design pattern
to create an iterator. The iterator sequentially visits various parts of a document such as elements and
attributes. You can inspect the type of the item under consideration to determine whether it’s a start tag, end
tag, or a text node. You can also read its attributes. Moreover, you can move the iterator to the next item. The
.NET Framework’s XmlReader falls in this category.
Parsers can also be classified as validating and nonvalidating. Validating parsers can validate an XML
document against a DTD or XML Schema as they parse the document. On the other hand, nonvalidating
parsers lack this ability.
■■Note LINQ to XML offers an in-memory way of reading and writing XML documents. You will learn
more about LINQ to XML later in this chapter. Chapter 13 covers the LINQ features as applicable to XML data
manipulation in fuller details.
XSLT
XML solves the problem of data representation and exchange. However, often we need to convert this XML
data into a format understood by the target application. For example, if your target is a web browser, the
XML data must be converted to HTML before displaying in the browser.
Another example is that of business-to-business (B2B) applications. Let’s say that application A
captures order data from the end user and represents it in some XML format. This data then needs to be sent
to application B that belongs to some other business. It is quite possible that the XML format as generated by
application A is different from that required by application B. In such cases, you need to convert the source
XML data to a format acceptable to the target system. In short, in real-world scenarios you need to transform
XML data from one form to another.
That is where XSLT comes in handy. XSLT stands for Extensible Style Sheet Language Transformations
and allows you to transform XML documents from one form into another. Figure 1-5 shows how this
transformation happens.
9
Chapter 1 ■ Introducing XML and the .NET Framework
XPath
Searching for and locating certain elements within an XML document is a fairly common task. XPath is
an expression language that allows you to navigate through elements and attributes in an XML document.
XPath consists of various XPath expressions and functions that you can use to look for and select elements
and attributes matching certain patterns. XPath is also a W3C recommendation. Figure 1-6 shows an
example of how XPath works.
10
Exploring the Variety of Random
Documents with Different Content
kuultuaan sinusta tällaisia asioita. Sinä olet sellainen poika, jota me
kaikki kunnioitamme ja josta me paljon pidämme. Minä luulen
myöskin huomanneeni, että toveriesi tunteet sinua kohtaan ovat
samanlaisia. Me olemme siitä ymmärtäneet, että sinun on ehkä
vaikeampi kuin muiden tunnustaa tehneesi halpamaista petosta. Kun
sinä nyt yrität valheella päästä eroon asiasta, olet sinä väärässä
luulossa, jos uskot valheen itseäsi paremmin auttavan kuin suoran,
rehellisen tunnustuksen. Me olemme päättäneet antaa sinulle
anteeksi tämän väärän luulon. Me toivomme, että sinä annat sille
oikean arvon, tajuat, että meidän hyvä mielipiteemme sinusta
velvoittaa sinua.
— O — olen, mutta…
Antti Bech pikemmin putosi kuin istui tuolilleen; hän laski päänsä
käsivarsilleen pöydälle ja voihki.
*****
Mikko Tiukkatuuli astui kotiin päin. Hänestä tuntui kuin eivät jalat
kannattaisi häntä; polvet notkuivat ja letkahtelivat.
Sitten hän nousi, meni vitkaan alas portaita, otti lakkinsa eteisestä.
Hän pysähtyi konttoorin oven taakse ja kuunteli. Isä oli sisällä. Hän
tarttui ovenripaan, pysähtyi, päästi irti taas ja meni ulos kadulle.
Hiljakseen hän astui katua; ajoneuvot tärskyivät ja kolisivat,
ihmiset kulkivat hänen ohitsensa; hän ei näyttänyt niitä näkevän eikä
kuulevan, hän kuvitteli olevansa kosteassa jääpuvussa.
Hän tuli aivan koulun ovelle saakka. Täällä hän pysähtyi ja pyyhki
otsaansa nenäliinalla; se tuli likomäräksi tuskanhiestä.
Kukaan ei vastannut.
— Kyllä, heti!
Hän liukui alas tuolilta. Hän saattoi tuskin seisoa tuskalta, hiipi
ovelle, tarttui avaimeen: ovi oli suljettu.
— Niin.
— No, mikä oli asia? Hän meni suuren työpöytänsä luo akkunan
eteen; rehtori istui ja tarjosi Mikko Tiukkatuulelle tuolia edessään.
— Selitä, poikaseni!
— Ei. Minä koetin saada sen niin saman näköiseksi kuin suinkin.
Rehtori oli taas kauan vaiti ja katseli ulos. Sitten hän kääntyi
vitkaan Mikko Tiukkatuulen puoleen ja sanoi:
— Niin.
Rehtori Holst antoi hänen itkeä pitkän aikaa. Kun kovin nyyhkytys
oli asettunut, kysyi hän:
Kun hän nyt vaan saisi sanotuksi kaikki tyyni Antti Bechille — niin
tulkoon sitten koko kurjuus.
Koulusta hänet nyt kaiketikin eroitettaisiin. Ja kotona isä ottaisi
puheeksi konepajan, tai merille lähdön, tai puotipaikan.
— Pa — paetako?
— Minä en kestä tätä kaikkea. Jos minut nyt ajetaan pois koulusta,
niin joutuu isäni aivan epätoivoon, häpeästä, näetkös. Molemmat, isä
ja äitikin. Heidän pitäisi kuitenkin keksiä minulle jotakin. Ehkä
lähettäisivät jonnekin muualle. Yhtä hyvinhän minä voin mennä itse.
Jo ajoissa. Sillä minä en kestä, en.
— Entä rahat?
— En tietystikään, mutta…
Mutta isän…!
Ei, hän tunsi itsessään: Hän ei voisi toista kertaa — ja vielä isälle!
Ja äitikin tulisi, — sisaret saisivat tietää!
Hän käveli ja käveli. Veri nousi päähän, koko ruumis aivan horjui.
Hän katsoi ympärilleen. Kaikkialla oli hiljaista, — kyllä hän oli hyvin
kaukana.
Hän oli matkalla maailmalle, oli todellakin paennut! Hän tahtoi
kulkea, kulkea yhä edelleen — eikä koskaan palata!
Mutta tämä oli ihan oikein. Hänen piti kärsiä puutetta. Tässä ei
auttanutkaan pelkkä rukoileminen. Ei, ensin hän saisi kärsiä jotakin
oikein kovaa. Nälkää ja puutetta, rahattomana, — jos hän tätä
kestäisi jonkun aikaa, edes muutamia päiviä, niin ehkä Jumala silloin
hiukan antaisi arvoa hänelle…!
— Sinä, Antti!
— Pelkäsikö hän?
— Kyllä, hän pelkäsi kovasti. Ja sitten hän sanoi, ettei uskaltaisi
mennä kotiin. Taikka oikeastaan hän tahtoi — tahtoi…
— Karata kotoa.
— Hyvin kernaasti!
— Kyllä!
— Niin on.
— Se väitti, tuota noin, ettei hänellä ole kotia, eikä mitään,
raukalla.
— No, Mikko! sanoi rehtori — kai sinä olet joka lauantai jäljentänyt
laskuesimerkkiä?
— Koetan.
— No, kai me nyt olemme yhtä mieltä siitä, ettei enää tapahdu
mitään petosta, Mikko?
— Kyllä.
— Silloin ei sinun tarvitse kestää sellaista päivää kuin eilinen oli.
Eikö totta, ethän sinä toista sellaista halua?
— En.
Minä en väitä mitään. Minä vaan kysyn, mistä sinä olet saanut minun
laskuni — ellet sinä ole jäljentänyt sitä!
Näin Simo Selmer rehenteli koulun pihalla. Antti Bech seisoi hänen
edessään uhitellen.
— Sen huomaan.
— Miten niin, huomaat?
— Kuinka, erilaisen?
— Täytyy — oho!
— Niin juuri — täytyy. Mitä sinä sillä tarkoitit, että olisi saatu
nähdä toista?
— Minä tarkoitan sitä, mitä tarkoitan. Antti Bech astui nyt ihan
hänen nenänsä eteen.
— Minä en luule mitään. Minä tiedän, että minun laskuni oli sinun
vihossasi.
— Mutta kun minä sanon — ja rehtori sanoo, — että se on
sattuma!
— Miten, merkillinen?
— Hyvin merkillinen.
— Hyvä on!
— Kunnollista sittenkin!
— Luuletko sinä, että rehtori olisi pyytänyt anteeksi, jos Antti olisi
tehnyt petoksen?
— E — en…!
Juuri silloin huomasi Antti, että hän olisi voinut pyöräyttää Nikon
pois päältänsä, päästä itse päällepäin ja antaa runsaasti takaisin;
sillä hän näki, että Makkaratikku itki vimmoissaan ja oli melkein
tajuttomana. Mutta hän pysyi alallaan, irroitti toisen kätensä ja sai
sen liivintaskuunsa, josta otti hyppysiinsä viisikolmattaäyrisen.
Antti Bech astui suoraan sen tynnyrin luo, jolla Simo Selmer istui
ja potki kantapäillään.
— Nyt saat hyökätä! sanoi Antti. Mutta Ville Gabrielsen astui esiin
joukosta ja sanoi juhlallisesti:
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com