Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
67% found this document useful (3 votes)
23 views

Java XML and JSON: Document Processing for Java SE Jeff Friesen All Chapters Instant Download

Jeff

Uploaded by

katkomonga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
67% found this document useful (3 votes)
23 views

Java XML and JSON: Document Processing for Java SE Jeff Friesen All Chapters Instant Download

Jeff

Uploaded by

katkomonga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Download the full version of the textbook now at textbookfull.

com

Java XML and JSON: Document Processing for


Java SE Jeff Friesen

https://textbookfull.com/product/java-xml-and-
json-document-processing-for-java-se-jeff-friesen/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Java XML and JSON: Document Processing for Java SE 2nd


Edition Jeff Friesen

https://textbookfull.com/product/java-xml-and-json-document-
processing-for-java-se-2nd-edition-jeff-friesen/

textbookfull.com

Java XML and JSON Friesen Jeff

https://textbookfull.com/product/java-xml-and-json-friesen-jeff/

textbookfull.com

Learn Java for Android Development Friesen Jeff

https://textbookfull.com/product/learn-java-for-android-development-
friesen-jeff/

textbookfull.com

Computer Networks 27th International Conference CN 2020


Gda■sk Poland June 23 24 2020 Proceedings Piotr Gaj

https://textbookfull.com/product/computer-networks-27th-international-
conference-cn-2020-gdansk-poland-june-23-24-2020-proceedings-piotr-
gaj/
textbookfull.com
Dark Kings (Feathers and Fate #1) 1st Edition Sadie Moss

https://textbookfull.com/product/dark-kings-feathers-and-fate-1-1st-
edition-sadie-moss/

textbookfull.com

Principles of Physiology for the Anaesthetist 4th Edition


Peter Kam

https://textbookfull.com/product/principles-of-physiology-for-the-
anaesthetist-4th-edition-peter-kam/

textbookfull.com

Computational Science and Its Applications ICCSA 2018 18th


International Conference Melbourne VIC Australia July 2 5
2018 Proceedings Part III Osvaldo Gervasi
https://textbookfull.com/product/computational-science-and-its-
applications-iccsa-2018-18th-international-conference-melbourne-vic-
australia-july-2-5-2018-proceedings-part-iii-osvaldo-gervasi/
textbookfull.com

The Future of the Law of the Sea Bridging Gaps Between


National Individual and Common Interests 1st Edition Gemma
Andreone (Eds.)
https://textbookfull.com/product/the-future-of-the-law-of-the-sea-
bridging-gaps-between-national-individual-and-common-interests-1st-
edition-gemma-andreone-eds/
textbookfull.com

Homelessness Handbook 1st Edition Levinson

https://textbookfull.com/product/homelessness-handbook-1st-edition-
levinson/

textbookfull.com
Mutual Insurance 1550-2015: From Guild Welfare and
Friendly Societies to Contemporary Micro-Insurers 1st
Edition Marco H. D. Van Leeuwen (Auth.)
https://textbookfull.com/product/mutual-insurance-1550-2015-from-
guild-welfare-and-friendly-societies-to-contemporary-micro-
insurers-1st-edition-marco-h-d-van-leeuwen-auth/
textbookfull.com
Java XML
and JSON
Document Processing for Java SE

Second Edition

Jef f Friesen
Java XML and JSON
Document Processing for Java SE
Second Edition

Jeff Friesen
Java XML and JSON: Document Processing for Java SE
Jeff Friesen
Dauphin, MB, Canada

ISBN-13 (pbk): 978-1-4842-4329-9 ISBN-13 (electronic): 978-1-4842-4330-5


https://doi.org/10.1007/978-1-4842-4330-5
Library of Congress Control Number: 2018968598

Copyright © 2019 by Jeff Friesen


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.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Jonathan Gennick
Development Editor: Laura Berendson
Coordinating Editor: Jill Balzano
Cover image designed by Freepik (www.freepik.com)
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/978-1-4842-4329-9. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
To my parents.
Table of Contents
About the Author����������������������������������������������������������������������������������������������������� xi

About the Technical Reviewer������������������������������������������������������������������������������� xiii


Acknowledgments���������������������������������������������������������������������������������������������������xv

Introduction�����������������������������������������������������������������������������������������������������������xvii

Part I: Exploring XML�������������������������������������������������������������������������������������� 1


Chapter 1: Introducing XML�������������������������������������������������������������������������������������� 3
What Is XML?�������������������������������������������������������������������������������������������������������������������������������� 3
Language Features Tour���������������������������������������������������������������������������������������������������������������� 5
XML Declaration���������������������������������������������������������������������������������������������������������������������� 5
Elements and Attributes���������������������������������������������������������������������������������������������������������� 7
Character References and CDATA Sections��������������������������������������������������������������������������� 10
Namespaces�������������������������������������������������������������������������������������������������������������������������� 12
Comments and Processing Instructions�������������������������������������������������������������������������������� 17
Well-Formed Documents������������������������������������������������������������������������������������������������������������ 17
Valid Documents������������������������������������������������������������������������������������������������������������������������� 18
Document Type Definition������������������������������������������������������������������������������������������������������ 19
XML Schema�������������������������������������������������������������������������������������������������������������������������� 26
Summary������������������������������������������������������������������������������������������������������������������������������������ 34

Chapter 2: Parsing XML Documents with SAX�������������������������������������������������������� 35


What Is SAX?������������������������������������������������������������������������������������������������������������������������������� 35
Exploring the SAX API������������������������������������������������������������������������������������������������������������������ 36
Obtaining a SAX 2 Parser������������������������������������������������������������������������������������������������������ 36
Touring XMLReader Methods������������������������������������������������������������������������������������������������� 37
Touring the Handler and Resolver Interfaces������������������������������������������������������������������������ 42

v
Table of Contents

Demonstrating the SAX API��������������������������������������������������������������������������������������������������������� 47


Creating a Custom Entity Resolver���������������������������������������������������������������������������������������������� 59
Summary������������������������������������������������������������������������������������������������������������������������������������ 65

Chapter 3: Parsing and Creating XML Documents with DOM��������������������������������� 67


What Is DOM?����������������������������������������������������������������������������������������������������������������������������� 67
A Tree of Nodes��������������������������������������������������������������������������������������������������������������������������� 68
Exploring the DOM API���������������������������������������������������������������������������������������������������������������� 71
Obtaining a DOM Parser/Document Builder�������������������������������������������������������������������������� 71
Parsing and Creating XML Documents���������������������������������������������������������������������������������� 73
Demonstrating the DOM API�������������������������������������������������������������������������������������������������������� 77
Parsing an XML Document���������������������������������������������������������������������������������������������������� 77
Creating an XML Document��������������������������������������������������������������������������������������������������� 82
Working with Load and Save������������������������������������������������������������������������������������������������������ 85
Loading an XML Document into a DOM Tree������������������������������������������������������������������������� 86
Configuring a Parser�������������������������������������������������������������������������������������������������������������� 90
Filtering an XML Document While Parsing���������������������������������������������������������������������������� 96
Saving a DOM Tree to an XML Document���������������������������������������������������������������������������� 100
Working with Traversal and Range������������������������������������������������������������������������������������������� 102
Performing Traversals���������������������������������������������������������������������������������������������������������� 102
Performing Range Operations��������������������������������������������������������������������������������������������� 107
Summary���������������������������������������������������������������������������������������������������������������������������������� 111

Chapter 4: Parsing and Creating XML Documents with StAX������������������������������� 113


What Is StAX?���������������������������������������������������������������������������������������������������������������������������� 113
Exploring StAX�������������������������������������������������������������������������������������������������������������������������� 114
Parsing XML Documents����������������������������������������������������������������������������������������������������� 115
Creating XML Documents���������������������������������������������������������������������������������������������������� 125
Summary���������������������������������������������������������������������������������������������������������������������������������� 138

vi
Table of Contents

Chapter 5: Selecting Nodes with XPath���������������������������������������������������������������� 139


What Is XPath?�������������������������������������������������������������������������������������������������������������������������� 139
XPath Language Primer������������������������������������������������������������������������������������������������������������ 139
Location Path Expressions�������������������������������������������������������������������������������������������������� 140
General Expressions������������������������������������������������������������������������������������������������������������ 143
XPath and DOM������������������������������������������������������������������������������������������������������������������������� 145
Advanced XPath������������������������������������������������������������������������������������������������������������������������ 154
Namespace Contexts����������������������������������������������������������������������������������������������������������� 154
Extension Functions and Function Resolvers���������������������������������������������������������������������� 156
Variables and Variable Resolvers���������������������������������������������������������������������������������������� 161
Summary���������������������������������������������������������������������������������������������������������������������������������� 164

Chapter 6: Transforming XML Documents with XSLT������������������������������������������� 165


What Is XSLT?��������������������������������������������������������������������������������������������������������������������������� 165
Exploring the XSLT API�������������������������������������������������������������������������������������������������������������� 166
Demonstrating the XSLT API������������������������������������������������������������������������������������������������������ 170
Going Beyond XSLT 1.0 and XPath 1.0�������������������������������������������������������������������������������������� 179
Downloading and Testing SAXON-HE 9.9����������������������������������������������������������������������������� 179
Playing with SAXON-HE 9.9������������������������������������������������������������������������������������������������� 180
Summary���������������������������������������������������������������������������������������������������������������������������������� 183

Part II: Exploring JSON������������������������������������������������������������������������������� 185


Chapter 7: Introducing JSON�������������������������������������������������������������������������������� 187
What Is JSON?�������������������������������������������������������������������������������������������������������������������������� 187
JSON Syntax Tour���������������������������������������������������������������������������������������������������������������������� 188
Demonstrating JSON with JavaScript��������������������������������������������������������������������������������������� 190
Validating JSON Objects����������������������������������������������������������������������������������������������������������� 195
Summary���������������������������������������������������������������������������������������������������������������������������������� 202

vii
Table of Contents

Chapter 8: Parsing and Creating JSON Objects with mJson�������������������������������� 205


What Is mJson?������������������������������������������������������������������������������������������������������������������������ 205
Obtaining and Using mJson������������������������������������������������������������������������������������������������� 206
Exploring the Json Class����������������������������������������������������������������������������������������������������������� 206
Creating Json Objects��������������������������������������������������������������������������������������������������������� 207
Learning About Json Objects����������������������������������������������������������������������������������������������� 213
Navigating Json Object Hierarchies������������������������������������������������������������������������������������� 223
Modifying Json Objects������������������������������������������������������������������������������������������������������� 225
Validation����������������������������������������������������������������������������������������������������������������������������� 232
Customization via Factories������������������������������������������������������������������������������������������������ 235
Summary���������������������������������������������������������������������������������������������������������������������������������� 242

Chapter 9: Parsing and Creating JSON Objects with Gson����������������������������������� 243


What Is Gson?��������������������������������������������������������������������������������������������������������������������������� 243
Obtaining and Using Gson��������������������������������������������������������������������������������������������������� 244
Exploring Gson�������������������������������������������������������������������������������������������������������������������������� 244
Introducing the Gson Class�������������������������������������������������������������������������������������������������� 245
Parsing JSON Objects Through Deserialization������������������������������������������������������������������� 248
Creating JSON Objects Through Serialization���������������������������������������������������������������������� 258
Learning More About Gson�������������������������������������������������������������������������������������������������� 267
Summary���������������������������������������������������������������������������������������������������������������������������������� 298

Chapter 10: Extracting JSON Values with JsonPath��������������������������������������������� 299


What Is JsonPath?�������������������������������������������������������������������������������������������������������������������� 299
Learning the JsonPath Language��������������������������������������������������������������������������������������������� 300
Obtaining and Using the JsonPath Library�������������������������������������������������������������������������������� 304
Exploring the JsonPath Library������������������������������������������������������������������������������������������������� 306
Extracting Values from JSON Objects���������������������������������������������������������������������������������� 306
Using Predicates to Filter Items������������������������������������������������������������������������������������������ 309
Summary���������������������������������������������������������������������������������������������������������������������������������� 321

viii
Table of Contents

Chapter 11: Processing JSON with Jackson�������������������������������������������������������� 323


What Is Jackson?���������������������������������������������������������������������������������������������������������������������� 323
Obtaining and Using Jackson���������������������������������������������������������������������������������������������� 324
Working with Jackson’s Basic Features����������������������������������������������������������������������������������� 325
Streaming���������������������������������������������������������������������������������������������������������������������������� 325
Tree Model��������������������������������������������������������������������������������������������������������������������������� 334
Data Binding������������������������������������������������������������������������������������������������������������������������ 340
Working with Jackson’s Advanced Features����������������������������������������������������������������������������� 350
Annotation Types����������������������������������������������������������������������������������������������������������������� 350
Custom Pretty Printers�������������������������������������������������������������������������������������������������������� 390
Factory, Parser, and Generator Features������������������������������������������������������������������������������ 398
Summary���������������������������������������������������������������������������������������������������������������������������������� 402

Chapter 12: Processing JSON with JSON-P���������������������������������������������������������� 405


What Is JSON-P?����������������������������������������������������������������������������������������������������������������������� 405
JSON-P 1.0�������������������������������������������������������������������������������������������������������������������������� 405
JSON-P 1.1�������������������������������������������������������������������������������������������������������������������������� 408
Obtaining and Using JSON-P����������������������������������������������������������������������������������������������� 410
Working with JSON-P 1.0���������������������������������������������������������������������������������������������������������� 411
Working with the Object Model API������������������������������������������������������������������������������������� 411
Working with the Streaming Model API������������������������������������������������������������������������������� 418
Working with JSON-P 1.1’s Advanced Features������������������������������������������������������������������������ 423
JSON Pointer����������������������������������������������������������������������������������������������������������������������� 424
JSON Patch�������������������������������������������������������������������������������������������������������������������������� 431
JSON Merge Patch��������������������������������������������������������������������������������������������������������������� 440
Editing/Transformation Operations�������������������������������������������������������������������������������������� 447
Java SE 8 Support��������������������������������������������������������������������������������������������������������������� 449
Summary���������������������������������������������������������������������������������������������������������������������������������� 456

ix
Table of Contents

Part III: Appendixes������������������������������������������������������������������������������������ 459


Appendix A: Answers to Exercises����������������������������������������������������������������������� 461
Chapter 1: Introducing XML������������������������������������������������������������������������������������������������������ 461
Chapter 2: Parsing XML Documents with SAX�������������������������������������������������������������������������� 466
Chapter 3: Parsing and Creating XML Documents with DOM���������������������������������������������������� 474
Chapter 4: Parsing and Creating XML Documents with StAX���������������������������������������������������� 486
Chapter 5: Selecting Nodes with XPath������������������������������������������������������������������������������������ 493
Chapter 6: Transforming XML Documents with XSLT���������������������������������������������������������������� 497
Chapter 7: Introducing JSON����������������������������������������������������������������������������������������������������� 501
Chapter 8: Parsing and Creating JSON Objects with mJson����������������������������������������������������� 503
Chapter 9: Parsing and Creating JSON Objects with Gson�������������������������������������������������������� 506
Chapter 10: Extracting JSON Values with JsonPath������������������������������������������������������������������ 510
Chapter 11: Processing JSON with Jackson����������������������������������������������������������������������������� 511
Chapter 12: Processing JSON with JSON-P������������������������������������������������������������������������������ 515

Index��������������������������������������������������������������������������������������������������������������������� 519

x
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
About the Author
Jeff Friesen is a freelance teacher and software developer
with an emphasis on Java. In addition to authoring Java I/O,
NIO and NIO.2 (Apress), Java Threads and the Concurrency
Utilities (Apress), and the first edition of this book, Jeff has
written numerous articles on Java and other technologies
(such as Android) for JavaWorld (JavaWorld.com), informIT
(InformIT.com), Java.net, SitePoint (SitePoint.com),
and other web sites. Jeff can be contacted via his web site
at JavaJeff.ca or via his LinkedIn (LinkedIn.com) profile
(www.linkedin.com/in/javajeff).

xi
About the Technical Reviewer
Massimo Nardone has more than 24 years of experiences
in Security, web/mobile development, Cloud, and IT
architecture. His true IT passions are Security and Android.
He has been programming and teaching how to program
with Android, Perl, PHP, Java, VB, Python, C/C++, and
MySQL for more than 20 years.
He holds a Master of Science degree in Computing
Science from the University of Salerno, Italy.
He has worked as a Project Manager, Software Engineer,
Research Engineer, Chief Security Architect, Information
Security Manager, PCI/SCADA Auditor, and Senior Lead IT Security/Cloud/SCADA
Architect for many years.
His technical skills include Security, Android, Cloud, Java, MySQL, Drupal, Cobol,
Perl, web and mobile development, MongoDB, D3, Joomla, Couchbase, C/C++, WebGL,
Python, Pro Rails, Django CMS, Jekyll, Scratch, etc.
He worked as visiting lecturer and supervisor for exercises at the Networking
Laboratory of the Helsinki University of Technology (Aalto University). He holds four
international patents (PKI, SIP, SAML, and Proxy areas).
He currently works as Chief Information Security Officer (CISO) for Cargotec Oyj,
and he is member of ISACA Finland Chapter Board.
Massimo has been reviewing more than 45 IT books for different publishing
companies, and he is the coauthor of Pro Android Games (Apress, 2015), Pro JPA 2 in
Java EE 8 (APress 2018), and Beginning EJB in Java EE 8 (Apress, 2018).

xiii
Acknowledgments
I thank Apress Acquisition Editor Jonathan Gennick and the Apress Editorial Board for
giving me the opportunity to create this second edition. I also thank Editor Jill Balzano
for guiding me through the book development process. Finally, I thank my technical
reviewer and copy editor for catching mistakes and making the book look great.

xv
Introduction
XML and (the more popular) JSON let you organize data in textual formats. This book
introduces you to these technologies along with Java APIs for integrating them into your
Java code. This book introduces you to XML and JSON as of Java 11.
Chapter 1 introduces XML, where you learn about basic language features (such
as the XML declaration, elements and attributes, and namespaces). You also learn
about well-formed XML documents and how to validate them via the Document Type
Definition and XML Schema grammar languages.
Chapter 2 focuses on Java’s SAX API for parsing XML documents. You learn how to
obtain a SAX 2 parser; you then tour XMLReader methods along with handler and entity
resolver interfaces. Finally, you explore a demonstration of this API and learn how to
create a custom entity resolver.
Chapter 3 addresses Java’s DOM API for parsing and creating XML documents. After
discovering the various nodes that form a DOM document tree, you explore the DOM
API, where you learn how to obtain a DOM parser/document builder and how to parse
and create XML documents. You then explore the Java DOM APIs related to the Load
and Save, and Traversal and Range specifications.
Chapter 4 places the spotlight on Java’s StAX API for parsing and creating XML
documents. You learn how to use StAX to parse XML documents with stream-based and
event-based readers and to create XML documents with stream-based and event-based
writers.
Moving on, Chapter 5 presents Java’s XPath API for simplifying access to a DOM
tree’s nodes. You receive a primer on the XPath language, learning about location path
expressions and general expressions. You also explore advanced features starting with
namespace contexts.
Chapter 6 completes my coverage of XML by targetting Java’s XSLT API. You learn
about transformer factories and transformers, and much more. You also go beyond the
XSLT 1.0 and XPath 1.0 APIs supported by Java.

xvii
Introduction

Chapter 7 switches gears to JSON. You receive an introduction to JSON, take a tour of
its syntax, explore a demonstration of JSON in a JavaScript context (because Java doesn’t
yet officially support JSON), and learn how to validate JSON objects in the context of
JSON Schema.
You’ll need to work with third-party libraries to parse and create JSON
documents. Chapter 8 introduces you to the mJson library. After learning how
to obtain and use mJson, you explore the Json class, which is the entry point for
working with mJSon.
Google has released an even more powerful library for parsing and creating JSON
documents. The Gson library is the focus of Chapter 9. In this chapter, you learn how
to parse JSON objects through deserialization, how to create JSON objects through
serialization, and much more.
Chapter 10 focuses on the JsonPath API for performing XPath-like operations on
JSON documents.
Chapter 11 introduces you to Jackson, a popular suite of APIs for parsing and
creating JSON documents.
Chapter 12 introduces you to JSON-P, an Oracle API that was planned for inclusion in
Java SE, but was made available to Java EE instead.
Each chapter ends with assorted exercises that are designed to help you master the
content. Along with long answers and true/false questions, you are often confronted
with programming exercises. Appendix A provides the answers and solutions.
Thanks for purchasing this book. I hope you find it helpful in understanding XML
and JSON in a Java context.
Jeff Friesen (October 2018)

Note You can download this book’s source code by pointing your web browser to
www.apress.com/9781484243299 and clicking the Source Code tab followed
by the Download Now link.

xviii
PART I

Exploring XML
CHAPTER 1

Introducing XML
Applications commonly use XML documents to store and exchange data. XML defines
rules for encoding documents in a format that is both human-readable and machine-­
readable. Chapter 1 introduces XML, tours the XML language features, and discusses
well-formed and valid documents.

What Is XML?
XML (eXtensible Markup Language) is a meta-language (a language used to describe
other languages) for defining vocabularies (custom markup languages), which is the key
to XML’s importance and popularity. XML-based vocabularies (such as XHTML) let you
describe documents in a meaningful way.
XML vocabulary documents are like HTML (see http://en.wikipedia.org/
wiki/HTML) documents in that they are text-based and consist of markup (encoded
descriptions of a document’s logical structure) and content (document text not
interpreted as markup). Markup is evidenced via tags (angle bracket–delimited syntactic
constructs), and each tag has a name. Furthermore, some tags have attributes (name/
value pairs).

Note XML and HTML are descendants of Standard Generalized Markup Language
(SGML), which is the original meta-language for creating vocabularies—XML is
essentially a restricted form of SGML, while HTML is an application of SGML. The
key difference between XML and HTML is that XML invites you to create your own
vocabularies with their own tags and rules, whereas HTML gives you a single
pre-created vocabulary with its own fixed set of tags and rules. XHTML and other
XML-based vocabularies are XML applications. XHTML was created to be a cleaner
implementation of HTML.

3
© Jeff Friesen 2019
J. Friesen, Java XML and JSON, https://doi.org/10.1007/978-1-4842-4330-5_1
Chapter 1 Introducing XML

If you haven’t previously encountered XML, you might be surprised by its simplicity
and how closely its vocabularies resemble HTML. You don’t need to be a rocket scientist
to learn how to create an XML document. To prove this to yourself, check out Listing 1-1.

Listing 1-1. XML-Based Recipe for a Grilled Cheese Sandwich

<recipe>
   <title>
      Grilled Cheese Sandwich
   </title>
   <ingredients>
      <ingredient qty="2">
         bread slice
      </ingredient>
      <ingredient>
         cheese slice
      </ingredient>
      <ingredient qty="2">
         margarine pat
      </ingredient>
   </ingredients>
   <instructions>
      Place frying pan on element and select medium heat.
      For each bread slice, smear one pat of margarine on
      one side of bread slice. Place cheese slice between
      bread slices with margarine-smeared sides away from
      the cheese. Place sandwich in frying pan with one
      margarine-smeared side in contact with pan. Fry for
      a couple of minutes and flip. Fry other side for a
      minute and serve.
   </instructions>
</recipe>

4
Chapter 1 Introducing XML

Listing 1-1 presents an XML document that describes a recipe for making a grilled
cheese sandwich. This document is reminiscent of an HTML document in that it consists
of tags, attributes, and content. However, that’s where the similarity ends. Instead of
presenting HTML tags such as <html>, <head>, <img>, and <p>, this informal recipe
language presents its own <recipe>, <ingredients>, and other tags.

Note Although Listing 1-1’s <title> and </title> tags are also found in
HTML, they differ from their HTML counterparts. Web browsers typically display
the content between these tags in their title bars or tab headers. In contrast, the
content between Listing 1-1’s <title> and </title> tags might be displayed as
a recipe header, spoken aloud, or presented in some other way, depending on the
application that parses this document.

Language Features Tour


XML provides several language features for use in defining custom markup languages:
XML declaration, elements and attributes, character references and CDATA sections,
namespaces, and comments and processing instructions. You will learn about these
language features in this section.

X
 ML Declaration
An XML document usually begins with the XML declaration, special markup telling an
XML parser that the document is XML. The absence of the XML declaration in Listing 1-­1
reveals that this special markup isn’t mandatory. When the XML declaration is present,
nothing can appear before it.
The XML declaration minimally looks like <?xml version="1.0"?> in which the
nonoptional version attribute identifies the version of the XML specification to which
the document conforms. The initial version of this specification (1.0) was introduced in
1998 and is widely implemented.

5
Chapter 1 Introducing XML

Note The World Wide Web Consortium (W3C), which maintains XML, released
version 1.1 in 2004. This version mainly supports the use of line-ending characters
used on EBCDIC platforms (see http://en.wikipedia.org/wiki/EBCDIC)
and the use of scripts and characters that are absent from Unicode (see h­ ttp://
en.wikipedia.org/wiki/Unicode) 3.2. Unlike XML 1.0, XML 1.1 isn’t widely
implemented and should be used only when its unique features are needed.

XML supports Unicode, which means that XML documents consist entirely of
characters taken from the Unicode character set. The document’s characters are
encoded into bytes for storage or transmission, and the encoding is specified via the
XML declaration’s optional encoding attribute. One common encoding is UTF-8 (see
http://en.wikipedia.org/wiki/UTF-8), which is a variable-length encoding of the
Unicode character set. UTF-8 is a strict superset of ASCII (see http://en.wikipedia.
org/wiki/ASCII), which means that pure ASCII text files are also UTF-8 documents.

Note In the absence of the XML declaration or when the XML declaration’s
encoding attribute isn’t present, an XML parser typically looks for a special
character sequence at the start of a document to determine the document’s
encoding. This character sequence is known as the byte-order-mark (BOM) and
is created by an editor program (such as Microsoft Windows Notepad) when it
saves the document according to UTF-8 or some other encoding. For example,
the hexadecimal sequence EF BB BF signifies UTF-8 as the encoding. Similarly,
FE FF signifies UTF-16 (see http://en.wikipedia.org/wiki/UTF-16) big
endian, FF FE signifies UTF-16 little endian, 00 00 FE FF signifies UTF-32
(see http://en.wikipedia.org/wiki/UTF-32) big endian, and FF FE 00
00 signifies UTF-32 little endian. UTF-8 is assumed when no BOM is present.

If you’ll never use characters apart from the ASCII character set, you can probably
forget about the encoding attribute. However, when your native language isn’t English
or when you’re called to create XML documents that include non-ASCII characters, you
need to properly specify encoding. For example, when your document contains ASCII
plus characters from a non-English Western European language (such as ç, the cedilla

6
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Chapter 1 Introducing XML

used in French, Portuguese, and other languages), you might want to choose ISO-8859-­1
as the encoding attribute’s value—the document will probably have a smaller size when
encoded in this manner than when encoded with UTF-8. Listing 1-2 shows you the
resulting XML declaration.

Listing 1-2. An Encoded Document Containing Non-ASCII Characters

<?xml version="1.0" encoding="ISO-8859-1"?>


<movie>
   <name>Le Fabuleux Destin d'Amélie Poulain</name>
   <language>français</language>
</movie>

The final attribute that can appear in the XML declaration is standalone. This
optional attribute, which is only relevant with DTDs (discussed later), determines
whether or not there are external markup declarations that affect the information passed
from an XML processor (a parser) to the application. Its value defaults to no, implying
that there are or may be such declarations. A yes value indicates that there are no such
declarations. For more information, check out “The standalone pseudo-attribute is only
relevant if a DTD is used” (www.xmlplease.com/xml/standalone/).

E lements and Attributes


Following the XML declaration is a hierarchical (tree) structure of elements, where an
element is a portion of the document delimited by a start tag (such as <name>) and an end
tag (such as </name>), or is an empty-element tag (a standalone tag whose name ends
with a forward slash [/], such as <break/>). Start tags and end tags surround content and
possibly other markup, whereas empty-element tags don’t surround anything. Figure 1-1
reveals Listing 1-1’s XML document tree structure.

7
Chapter 1 Introducing XML

recipe

title ingredients instructions

ingredient ingredient ingredient

Figure 1-1. Listing 1-1’s tree structure is rooted in the recipe element

As with HTML document structure, the structure of an XML document is anchored


in a root element (the topmost element). In HTML, the root element is html (the <html>
and </html> tag pair). Unlike in HTML, you can choose the root element for your XML
documents. Figure 1-1 shows the root element to be recipe.
Unlike the other elements, which have parent elements, recipe has no parent. Also,
recipe and ingredients have child elements: recipe’s children are title, ingredients,
and instructions; and ingredients’ children are three instances of ingredient. The
title, instructions, and ingredient elements don’t have child elements.
Elements can contain child elements, content, or mixed content (a combination of
child elements and content). Listing 1-2 reveals that the movie element contains name
and language child elements and also reveals that each of these child elements contains
content (e.g., language contains français). Listing 1-3 presents another example that
demonstrates mixed content along with child elements and content.

Listing 1-3. An Abstract Element Containing Mixed Content

<?xml version="1.0"?>
<article title="The Rebirth of JavaFX" lang="en">
   <abstract>
      JavaFX 2 marks a significant milestone in the history
      of JavaFX. Now that Sun Microsystems has passed the
      torch to Oracle, JavaFX Script is gone and
      JavaFX-oriented Java APIS (such as

8
Chapter 1 Introducing XML

      <code>javafx.application.Application</code>) have
      emerged for interacting with this technology. This
      article introduces you to this refactored JavaFX,
      where you learn about JavaFX 2 architecture and key
      APIs.
   </abstract>
   <body>
   </body>
</article>

This document’s root element is article, which contains abstract and body child
elements. The abstract element mixes content with a code element, which contains
content. In contrast, the body element is empty.

Note As with Listings 1-1 and 1-2, Listing 1-3 also contains whitespace (invisible
characters such as spaces, tabs, carriage returns, and line feeds). The XML
specification permits whitespace to be added to a document. Whitespace appearing
within content (such as spaces between words) is considered part of the content. In
contrast, the parser typically ignores whitespace appearing between an end tag and
the next start tag. Such whitespace isn’t considered part of the content.

An XML element’s start tag can contain one or more attributes. For example,
Listing 1-1’s <ingredient> tag has a qty (quantity) attribute, and Listing 1-3’s
<article> tag has title and lang attributes. Attributes provide additional details
about elements. For example, qty identifies the amount of an ingredient that can be
added, title identifies an article’s title, and lang identifies the language in which the
article is written (en for English). Attributes can be optional. For example, when qty
isn’t specified, a default value of 1 is assumed.

Note Element and attribute names may contain any alphanumeric character


from English or another language and may also include the underscore (_), hyphen
(-), period (.), and colon (:) punctuation characters. The colon should only be used
with namespaces (discussed later in this chapter), and names cannot contain
whitespace.

9
Chapter 1 Introducing XML

Character References and CDATA Sections


Certain characters cannot appear literally in the content that appears between a start
tag and an end tag or within an attribute value. For example, you cannot place a literal
< character between a start tag and an end tag because doing so would confuse an XML
parser into thinking that it had encountered another tag.
One solution to this problem is to replace the literal character with a character
reference, which is a code that represents the character. Character references are
classified as numeric character references or character entity references:

• A numeric character reference refers to a character via its Unicode


code point and adheres to the format &#nnnn; (not restricted to
four positions) or &#xhhhh; (not restricted to four positions), where
nnnn provides a decimal representation of the code point and hhhh
provides a hexadecimal representation. For example, &#0931; and
&#x03A3; represent the Greek capital letter sigma. Although XML
mandates that the x in &#xhhhh; be lowercase, it’s flexible in that
the leading zero is optional in either format and in allowing you
to specify an uppercase or lowercase letter for each h. As a result,
&#931;, &#x3A3;, and &#x03a3; are also valid representations of the
Greek capital letter sigma.

• A character entity reference refers to a character via the name of


an entity (aliased data) that specifies the desired character as its
replacement text. Character entity references are predefined by XML
and have the format &name;, in which name is the entity’s name.
XML predefines five character entity references: < (<), > (>), & (&),
&apos; ('), and &quot; (").

Consider <expression>6 < 4</expression>. You could replace the < with numeric
reference &#60;, yielding <expression>6 &#60; 4</expression>, or better yet with <,
yielding <expression>6 < 4</expression>. The second choice is clearer and easier to
remember.

10
Chapter 1 Introducing XML

Suppose you want to embed an HTML or XML document within an element. To


make the embedded document acceptable to an XML parser, you would need to replace
each literal < (start of tag) and & (start of entity) character with its < and & predefined
character entity reference, a tedious and possibly error-prone undertaking—you might
forget to replace one of these characters. To save you from tedium and potential errors,
XML provides an alternative in the form of a CDATA (character data) section.
A CDATA section is a section of literal HTML or XML markup and content
surrounded by the <![CDATA[ prefix and the ]]> suffix. You don’t need to specify
predefined character entity references within a CDATA section, as demonstrated in
Listing 1-4.

Listing 1-4. Embedding an XML Document in Another Document’s CDATA


Section
<?xml version="1.0"?>
<svg-examples>
   <example>
      The following Scalable Vector Graphics document
      describes a blue-filled and black-stroked
      rectangle.
      <![CDATA[<svg width="100%" height="100%"
           version="1.1"
           xmlns="http://www.w3.org/2000/svg">
         <rect width="300" height="100"
               style="fill:rgb(0,0,255);stroke-width:1;
                      stroke:rgb(0,0,0)"/>
      </svg>]]>
   </example>
</svg-examples>

Listing 1-4 embeds a Scalable Vector Graphics (SVG) [see http://en.wikipedia.


org/wiki/Scalable_Vector_Graphics] XML document within the example element of
an SVG examples document. The SVG document is placed in a CDATA section, obviating
the need to replace all < characters with < predefined character entity references.

11
Random documents with unrelated
content Scribd suggests to you:
These are inflicted as are wounds elsewhere, and, while always
serious, have an importance proportionate to the infection which may
have occurred with the injury or afterward. In practise it may be
assumed that the skin, like the clothing outside, is always dirty and
infected, and that every penetrating wound should be regarded as an
infected wound. Not every wound in the vicinity of a joint is
penetrating, and it is advisable to ascertain whether a joint cavity be
actually open, as much of the method of treatment will depend upon
this fact. The majority of these injuries are of the punctured or small
incised variety. The actual joint opening is usually smaller than that
in the skin. It may be so small as to escape observation. Outflow of
blood is not pathognomonic, but escape of synovial fluid always
indicates that some serous cavity, possibly a bursa or tendon sheath,
has been opened. Immediate accumulation of fluid within a joint after
probable wounding of the synovial membrane is quite suggestive, as
it is likely to imply that the joint is filling with blood. After any injury
which may loosen them the epiphyses should be carefully examined,
in order to determine if they have been loosened, while it should be
estimated, so far as possible, whether the epiphyseal junction has
been disturbed or is probably infected. The student should
remember that punctured wounds of joints are not necessarily made
from without inward. A spicule or fragment of bone may, by
protruding, produce exactly the same condition, only in this case
there may be a compound fracture to complicate it. Infection does
not invariably follow these injuries. Their gravity is in large degree
measured by the presence or absence of a suppurative synovitis.
This does not necessarily instantly follow the injury, but develops
within the ensuing two or three days. Therefore the fate of such a
joint is not necessarily determined by inspection within the first few
hours. Esmarch’s dictum regarding gunshot wounds may here be
paraphrased. The fate of every punctured joint depends upon the
man who first takes care of it. If the proper thing be done promptly a
good result may usually be obtained.
The first indication in every such case is sterilization of the parts,
including the area of the wound. If by a small elliptical incision the
wounded skin can be excised, it may perhaps very much improve
the prospect. A small punctured wound may be watched for a day or
two, especially if it be believed that the first attention were prompt
and antiseptic. Should no unpleasant features appear little need be
done except to apply ice externally and maintain rest. On the first
appearance of sepsis or of increasing trouble in the joint it should be
promptly incised, irrigated, and drained.
In the larger openings of joints it should be assumed from the
outset that infection has occurred. In such a case the wound margins
should be trimmed, the joint cavity thoroughly irrigated, and explored
for foreign bodies, by enlarging the existing opening. After thorough
irrigation a drain should be inserted for at least a few hours. For this
purpose a catgut strand or a drainage tube may be employed.
As soon as the presence of pus (acute pyarthrosis) is made clear
the case takes on a larger aspect, in that drainage not alone at one
point is indicated, but probably at two or three. Nothing is so
disastrous to an involved joint as pus retained within its hidden
recesses. Almost every other consideration is sacrificed to its
discovery and to affording a means for its escape. Counteropenings
in numbers sufficient for the purpose are, therefore, indicated, and it
will often be best to draw through the affected joint a drainage tube,
of a size sufficient to prevent its occlusion by thick pus or debris.
Daily and continuous irrigation may be practised to great advantage,
or, as is possible with the ankle, the wrist, or elbow, continuous
immersion may be substituted as a still better measure. Wherever
infection and destruction to this degree have taken place it may be
presumed that the future of the joint is seriously compromised. There
will, therefore, be room for display of judgment as to when to begin
passive and when active motion; moreover, a guarded prognosis
concerning restoration of function should be given.
Gunshot fractures of joints constitute almost a category by
themselves. Under the old regime, and in the pre-antiseptic era,
gunshot wounds of joints condemned one to amputation and loss of
at least the part below. The mortality attending injuries of this kind,
with the resulting amputations, during our Civil War, and all others
previous to it, was extreme. The Continental surgeons first
appreciated the value of antiseptic occlusion, and taught the rest of
the world that this wholesale sacrifice of limb, and often of life, was
unnecessary and could be avoided. Reyher’s first papers on this
subject revolutionized previous views and practises, and established
on a firm basis the general principle of primary antiseptic occlusion
of those injured joints. The accumulated experience of military
surgeons since his time, as well as of civil surgeons all over the
world, has demonstrated that if a gunshot wound of a joint be
afforded prompt antiseptic occlusion and rest the chances are in
favor of restoration of function, with a minimum of disturbance and a
maximum of result. It was because of these results that soldiers
were provided with the “first aid to the injured” packets, so that a
punctured wound might be protected immediately after its reception.
Even the complete tunnelling of a joint, which the Mauser bullets so
often accomplish, does not seem to be so serious an injury today as
was the puncture of a needle or an awl in the pre-antiseptic era.
Therefore the best thing to do with a gunshot wound is to practise
antiseptic occlusion. If it become troublesome it should be treated in
accordance with the advice given above.
This relegates the matter of amputation or of primary excision of
an injured joint to those cases of extensive and mutilating injury
where not only the soft structures are widely opened and infected,
but the joint ends of the bones also are seriously involved. When it
comes to the treatment of compound dislocations it is difficult to lay
down principles which shall be universally applicable. As a general
rule primary excision will usually be indicated, and prove not only
life-saving but limb-saving. In compound dislocations of the
astragalus its removal will be nearly always indicated. Only in cases
of extensive damage will amputation be necessary.
Inasmuch as it is infection, leading to suppurative synovitis or
arthritis, which gives to all serious cases their greatest dangers, it will
be sufficient at this point to remind the reader to this effect and to
describe the condition itself a little later.

SYNOVITIS AND ARTHRITIS.


The various surgical affections of a joint may be of primary or
secondary origin, and of rapid or chronic type. The acute are usually
expressions of serious infection, while the chronic are frequently of
toxemic origin, including under this heading manifestations of a
particular diathesis or defective metabolism. Others are so
exceedingly slow in their course and are so intimately connected
with other indications of disease of the central nervous system as to
be called neuropathic. (See below.)
Nearly all the acute affections begin in the synovial sac proper.
From this they may spread and involve the adjoining parts. The
acute toxic lesions also arise within the synovial cavity, such as
those which follow gonorrhea, typhoid, scarlatina, pneumonia,
influenza, etc. Tuberculosis may primarily affect either the synovia, in
which case we have a condition corresponding to tuberculous
peritonitis, or it may take its origin in the expanded bone ends or in
the epiphyseal cartilages. Syphilitic affections of the joints are rarely
acute. They lead rather to chronic disintegrations or hypertrophy. No
matter how the lesion may have arisen it will nearly always extend to
and involve other parts; thus in acute suppurations the articular
cartilages are soon attacked, while in the more chronic forms, which
have their origin in the bone, the joint cavity is slowly encroached
upon and its integrity impaired or destroyed.
So long as the type of joint disease be not destructive a complete
or nearly complete restoration of function can be expected, provided
suitable treatment be given early. If, however, a case occur only after
fibrinous outpour has organized into adhesions, muscles have
withered from disuse, and the entire joint become distorted or
disarranged, then it may be too late to cure, and it is a question then
of how much improvement can be effected. Even after acute
suppuration, if the case be properly managed from the outset, very
useful joints can be regained.
Dry Synovitis.—In synovitis, as in pleurisy, there may be a
minimum of serous outpour, such exudate as
escapes into the joint being exceedingly rich in fibrin and coagulating
easily. This material is variously disposed of, and may form
adhesions which will limit motion, or masses of condensed fibrin
which may be broken up into shreds or rounded off into seed-like or
rice-grain bodies. When tenderness subsides sufficiently to permit it
these may sometimes be felt within the joint. At other times they lead
later to an hydrarthrosis, which may prove more or less disabling and
require subsequent operation. Another form of synovitis sicca is met
with in acute and perhaps chronic rheumatism, where masses of
fibrin become loosened and can be felt as foreign bodies, or fringes,
beneath the joint covering.
Acute Synovitis.—The ordinary acute synovitis is characterized
by more or less effusion, and corresponds to
pleurisy with effusion. It is the result usually of external injury, or it is
combined with what has already been described as sprain. The fluid
outpour is watery, is rarely blood-stained, save in cases of
lacerations, usually distends the joint capsule, often to a painful
degree, but represents nothing more than the consequences of
hyperemia. If this fluid collection can be protected from
contamination by germs it will disappear under suitable treatment,
with a return to almost normal original conditions. Let it once become
contaminated, however, and the type of disease is quickly changed,
for there will then be an acute inflammation with its attendant
phenomena and consequences.
Treatment.—Cases of simple character are of short duration, i. e.,
one to two weeks. If seen early they should be treated by gentle
compression and the application of ice-cold, wet compresses. Heat
applied at this time may give temporary comfort, but will encourage
effusion. Even if a joint thus affected be not seen until the swelling is
extreme, wet compresses will still afford the simplest and the most
comforting method of treatment, although they need not now be kept
cold; in fact, gentle heat may now promote absorption. If the
compresses be moistened in salt solution, to which a little alcohol
has been added, the stimulating effect will probably be still greater.
Such a joint needs to be placed at rest, save perhaps in the case of
an ankle-joint or wrist-joint, which may be snugly strapped after
injury. In some of these latter cases the patient can resume use of
the joint almost at once.
Purulent Synovitis.—This rarely begins as a purulent condition,
but may be the result of the non-inflammatory
and non-purulent form. In such a case the character of the fluid
outpour soon merges into the seropurulent, and later become almost
nothing but pus. If the interior of a joint could be inspected, under
these conditions, the intensity and extent of the vascularity and
cellular changes going on within the synovial membrane and
beneath it would present a different picture from that of the non-
purulent form. The appearance of a joint interior, under these
circumstances, is similar to that of a well-marked purulent
conjunctivitis. Articular surfaces are quickly eroded or perforated,
while cartilages thus once affected are often loosened from their
attachments through necrosis and remain as foreign bodies in the
fluid collection. Even strong ligamentous tissues will melt down and
become so weakened as to permit a looseness of motion foreign to
the natural joint. In fact, as between purulent synovitis and acute
suppurative arthritis it is but a matter of extent of destruction, not of
character of lesion. In this way pathological dislocations are
produced, sometimes even within a few days, being the combined
result of destruction of ligaments and the pull of muscles which are
thrown into reflex spasm by the presence of intra-articular disease.
Not only do we see caries of the exposed bone ends, but epiphyseal
separations are not uncommon in the young, while every structure
around and outside of the joint participates, even to the extent of
abscess formation. Abscesses may form without the joint and work
into it, or the purulent collection within may escape at points of least
resistance and burrow, forming perhaps numerous foci at some
distance from the joint first affected. If such a case is to be saved it
will require numerous openings and counteropenings, with free
drainage, while even then there can be no expectation of restoring
joint function. There is, then, in these cases at least a sacrifice of
joint, sometimes of limb, and in neglected cases of life itself.
Symptoms.—Of the large joints only the shoulder and hip,
especially the latter, are placed so deeply as not to permit of easy
examination and diagnosis. Pain, swelling, and loss of function, with
or without history of injury, will predominate in well-marked cases,
while very early in most, and promptly in all, there will occur reflex
spasm of those muscles which have to do with motion of the affected
parts, by which they become more or less fixed and beyond
voluntary control of the patient. This condition has been described by
Sayre as “muscles on guard.” It is a significant feature, and has as
much to do with active joint disease as has abdominal rigidity with
surgical intra-abdominal conditions. Swelling will be proportionate to
the acuteness of the case. Tenderness is nearly always extreme,
especially along the articular line. The joint capsule is frequently
distended to its extreme and the normal contour of the part
completely obliterated.
The most common position in which limbs are held is midway
between extremes; thus when the knee is involved the leg will
become flexed upon the thigh, at about 75 degrees. If the shoulder
be at fault the arm is maintained close to the body. In disease of the
elbow the forearm is carried midway between the right angle and
complete extension. This is partly due to the fact that the flexors are
always stronger than the extensors, as it represents a compromise
between the antagonism of the opposing groups of muscles.
Pus, when present, is commonly also manifested by the usual
signs of its existence. There will be pitting on pressure or edema of
the overlying parts, while an acutely inflamed joint may be at any
time so swollen as to impede return circulation and lead to edema of
the parts beyond. To the local signs of phlegmon, then, we simply
have to add in greater detail those mentioned above. Along with
these there will be constitutional septic disturbances, usually
proportionate to the gravity of the local condition. The opportunities
for absorption afforded by a large synovial surface are great, and the
lymphatics are sure to carry toxins in abundance. The signs, then, of
septicemia, sometimes even of pyemia, are often pronounced. In the
presence of a joint full of pus the prognosis may be regarded as
exceedingly grave. Pain and tenderness seem to bear but little
relation to the swelling. Usually pain is an expression of distention,
yet some of the non-inflammatory forms of apparently milder type
are extremely painful. Pain is influenced by the position of the joint,
and the patient instinctively seeks that position in which suffering is
minimized. In a joint disorganized by the presence of pus there is
less sensitiveness, except on rough handling, unless the trouble
have extended far beyond the joint limits, and cellulitis be present,
with suppuration threatening. In metastatic joint abscess tenderness
rather than pain is the common rule.
In the presence of an acute inflammation in the joint end of a long
bone the other joint structures will participate to an extent
proportionate to its acuteness. With an acute osteomyelitis—e. g.,
near the articular surface—the synovial membrane will participate,
just as does the pleura in many cases of pneumonia, and we may
look for fluid in the joint in one case as we do for fluid in the chest
cavity in the other. Moreover, pictures of acute or chronic tuberculous
affections of the synovia correspond very closely to those of the
pleura. Tuberculous disease is liable to spread in every direction in
both diseases. The reverse of this, however, is not true in all
diseases of the chest, and there are many synovial as well as pleural
affections which are confined to their respective sacs.
The same statement, almost, can be made concerning the bursæ
and tendon sheaths in proximity to infected joints. Particularly is this
true when any of these connect with joint cavities.
The metastatic forms of pyarthrosis, as a collection of pus within
the joint capsule is called, are more insidious, though sometimes
equally destructive. They are by no means confined to one joint, and
in pyemia especially many of the joints will become involved. (See
Pyemia.) These secondary affections seem to be purulent from the
outset. In gonorrhea the effused fluids will often be found nearly pure
cultures of the gonococcus; after typhoid they contain typhoid bacilli,
etc. Such expressions are less frequent after pneumonia, influenza,
and the acute exanthemas, but may be seen even after smallpox. It
is often in these severely destructive joint lesions that spontaneous
dislocation occurs (Fig. 193).
—In the presence of a single joint lesion indications for treatment are
quite clear. When we have multiple and pyemic or gonorrheal
pyarthrosis it is often exceedingly difficult to determine what is for the
best interest of the patient. In general it may be said that pyemia
progressed to this extent will almost certainly be fatal, and we may
rest content with aspirating the affected joints, or perhaps in leaving
them alone; because we may feel that they constitute but a small
proportion of the metastatic foci which eventually determine death.
On the other hand, in other infections with pyarthrosis it would be
better to aspirate or to open and drain, because these cases are
slow and chronic, and the exudate is sometimes so rich in fibrin as to
lead to quite firm spurious ankylosis.
Thus gonorrheal synovitis is usually monarticular, although several
joints may be involved. It is readily recognized in the presence of the
active disease, but there are times when recognition is made difficult
Fig. 193 Treatment.by the
latency of urethral
symptoms or the
concealment of their
existence. The knee
is usually the joint
most often involved;
next the joints about
the foot, and
sometimes the
tendon sheaths and
bursæ adjoining
them.
Syphilitic arthritis is
a chronic and mildly
but steadily
progressive affection.
It rarely assumes
purulent form without
some secondary
infection. It is
frequently combined
with gumma along the
epiphyseal border. In
hereditary syphilis
numerous joints may
be involved in
Pneumococcus infection of ankle; rapid destruction of changes of the
all joint structures. Child aged nine months. (Lexer.) rachitic type.
Gout or some of its
allied rheumatoid manifestations may lead to a dry form of synovitis,
with deposit of urates or of lymph, and the formation of tophi in the
neighborhood, or it may assume the form of a chronic and intractable
hydrarthrosis. The acute forms are accompanied by great pain, with
redness and swelling, peri-articular and intra-articular. The tendency
of these cases is to chronicity and recurrence.
General Treatment.
—Upon the nature of the condition will depend the treatment of joint
diseases. The questions of when to operate and when to abstain,
when to enforce rest and when to begin passive and when active
motion, call for discriminating judgment. An acute or even mild
traumatic synovitis should, first of all, be protected from becoming
purulent. Should injury be accompanied by a bruise, the greatest
care should be given to antisepsis, and the part sterilized and
dressed with every precaution. Should there be no external injury we
may rely ordinarily upon cold, wet compresses, with suitable elastic
compression and physiological rest. Should two or three days of this
treatment fail to bring about nearly complete resorption the aspirator
may be employed to withdraw the fluid. If this should be found to be
bloody or too thick to run through the needle, it will be advisable to
make small incisions on either side, under the strictest precautions,
and to practise thorough irrigation, by which the joint cavity will be
completely cleared of foreign material. As soon, however, as the
presence of pus is indicated, or even suspected, the whole character
of the treatment should change. The surgeon should now endeavor
to be as radical as possible. The more purulent the collection the
more are free incision, irrigation, and drainage indicated and the
more complicated the condition the more he should make
counteropenings here and there, wherever joint pockets may be
emptied.
When muscle spasm not only seriously disturbs the patient but
threatens to draw the limb into an undesirable position it should be
overcome, either by employment of traction with weight and pulley,
or by forcible reposition and fixation in suitable splints, such as
plaster of Paris. Some of the most extensive operations that are
called for are necessitated by neglect to observe these precautions
early. Often nothing will afford so much relief as the use of traction,
with sufficient weight, tiring out contracted muscles, and thus not
actually separating joint surfaces, but overcoming that muscle spasm
which brings them tightly together and thus gives pain.
In the more chronic form of cases absorption may be promoted by
elastic compression, by massage, by wet compresses, and
sometimes by blistering. Ordinarily, and especially in those cases
characterized by pain, more can be accomplished with the actual
cautery drawn lightly and rapidly over the surface of the joint than by
blistering. This application is referred to as the flying cautery, and it
is one of the most effective agents known for the relief of deep-
seated pain, as well as of cutaneous hyperesthesia. Its use causes
little if any unpleasant sensation, and should be repeated at daily
intervals until the primary object is attained.
Should aspiration of a distended joint be practised at any time, one
should atone for the loss of intra-articular pressure thereby produced
by external compression, preferably with an elastic medium.
In the writer’s opinion it is not advisable to use a small aspirating
trocar in those cases which are likely to call for irrigation. The
aspirating needle should be confined to the non-purulent collections
of fluid, although some surgeons advise and practise throwing into a
mildly infected joint, through such a needle, some reasonably strong
antiseptic fluid or emulsion, hoping thus to gain its bactericidal effect
without external incision.
The active manifestations of disease being mastered, one
addresses himself naturally to the greatest possible prevention of
deformity and restoration of function. Indeed, these should be kept in
view from the outset, although we have, for a time, to disregard them
in favor of more imperative indications. If ankylosis appear inevitable
the joint should be kept in that position in which, when stiff, it will be
most useful. This position will be, at the elbow, at a right angle; at the
hip or knee, nearly complete extension. When, on the other hand,
restoration of function is hoped for it will be obtained through a
combination of massage, active and passive movements, with the
use perhaps of some sorbefacient ointment, such as the compound
ichthyol-mercurial, or by the nearly constant use of cold, wet
compresses, combined with the other measures. The greatest care
should be exercised in determining the time when absolute rest
given to an inflamed joint should be changed to the gentle or more
forcible movements required for restoring use to previously inflamed
joint surfaces.
Chronic Synovitis and Arthritis.—A chronic serous effusion into
a joint is given the term
hydrarthrosis. This condition is never primary; it is always the residue
of some previous acute lesion, or else it is the result of neuropathic
or rheumatoid changes going on in and about the joint, accompanied
by relaxation of membranes permitting passive distention with fluid.
The contained fluid is ordinarily pure serum. It may contain a little
blood or numerous particles or shreds of fibrin, while in rare
instances there will be found in it drops of oil or even fat crystals.
The degree of distention of a joint capsule is the measure of the
gravity of the case, as this membrane, like any other, will yield to
gradual distention, although it at the same time undergoes thickening
as a protective measure. Thus the synovia may, under certain
circumstances, become as thick as the pleura. The result is a tough,
leathery condition of this membrane, which makes it exceedingly
difficult to manage. The joint thus involved will appear more
prominent than it should, because of the atrophy of the surrounding
structures. Accurate comparisons can only be made by measuring
corresponding joints. Neighboring bursæ and tendon sheaths often
participate in the distention. These collections are ordinarily painless,
or nearly so, but interfere, to varying extent, with the function of the
joint. Anatomical outlines disappear or are concealed by the bag of
fluid. It is rare that there are any constitutional symptoms except
perhaps those of the disease which causes the disturbance. The
amount of fluid which may be contained in a long-distended knee-
joint, for instance, is relatively very large. The prognosis in these
cases will depend much upon the underlying cause, as well as upon
the age, vitality, and docility of the patient.
Treatment.—Removal of the fluid is always the indication. After
reasonable effort has shown that this is not possible by the
employment of massage, the actual cautery and elastic
compression, combined with functional rest, it should be withdrawn
by the aspirating needle or trocar. The more experience, however,
we have with affections of this class the more we will realize that the
interior of the synovial membrane is frequently studded with
deposits, fringes, etc., which are not affected by mere aspiration, and
the more cogent argument will be gained for sufficiently free incision
to permit inspection of the interior of the joint, removal of tags of
tissue, thorough washing out and sponging, by which a change in
circulation and nutrition is certainly affected; and this may be
combined with excision of a liberal portion of the thickened
membrane, by which the dimensions of the joint may be materially
reduced when the opening is sutured. For long-standing cases of
well-marked hydrarthrosis, especially in the knee, the writer would
urge this method of treatment. Drainage, if called for at all, can be
made with strands of silkworm, or some temporary material which
will quickly disappear or be promptly removed. This is particularly
applicable for the milder forms of tuberculous synovitis, in which the
joint is thus treated on the same principle that is applied in washing
out a tuberculous peritoneal cavity.

ARTHRITIS DEFORMANS AND OSTEO-ARTHRITIS.


Under this general name have been grouped a number of
conditions, including the so-called rheumatoid arthritis, and referring
to a variety of chronic progressive lesions of joints which involve the
articular cartilages and synovial membranes, later the bones, and
which produce more or less loss of function and deformity. Although
often spoken of as “rheumatoid,” the condition has nothing to do with
rheumatism as such, whatever that may be. It moreover presents no
analogies to the forms of acute synovitis already described. These
lesions are more common in women than in men, occurring oftener
in those who have been sterile, and during or after the menopause.
So far as their etiology and pathology are concerned, it is true,
though it seem trite to say it, that they are the result of disturbed
nutrition, which itself may be referred back to perverted trophic
influences. Exposure, bad hygienic surroundings, improper food,
mental perturbation, and depression are more or less potent factors
in most of the cases. In some instances occurring in advanced age
they seem to be due to changes ordinarily regarded as senile. When
joint lesions are multiple and symmetrical, and accompanied by
other nutritive changes, we may refer the cause back to the central
nervous system. When monarticular they are more likely to be the
residue of some previous infection or injury, such as gonorrhea,
influenza, or an acute exanthem. If in connection with the joint
manifestations we find the spleen and lymphatics enlarged, then the
case may be regarded as doubtless infectious in nature.
Fig. 194 The pathological changes
within these joints include almost
every imaginable alteration.
Bones soften and atrophy at one
point, or at another become
enlarged and thickened, and
throw out osteophytic projections
by which the whole shape of the
joint is materially changed.
Cartilages atrophy here and
thicken there, and disappear, at
times, to an extent by which
bone is exposed, the exposed
surfaces frequently becoming
polished or eburnated. The
position of the joint and its
general contour may be
materially altered by these
changes, and marked deformity
or notable enlargement result.
Subluxations are not infrequent,
while the ligamentous structures
are sufficiently strong to perform
their function, and the joint yields
or “wabbles.” Meanwhile the
synovial membrane undergoes
corresponding changes, and
becomes distended with fluid so
that hydrarthrosis is a frequent
accompaniment.
On the other hand, there is
another type of analogous
changes where the tendency is
Arthritis deformans, knee. (Ransohoff.) atrophic throughout and little if
any extra fluid accumulates.
Such a joint may become smaller rather than larger, especially if, as
in some cases, some part of the bone practically disappears.
At all events muscle atrophy, sometimes with pseudo-ankylosis,
sometimes with actual ankylosis, will characterize most of these
cases, and muscles naturally disappear as they functionate less and
less.
Pain is an irregular feature, some of the lesions being quite
painful, others almost free from it. The lesions are essentially
progressive in their character, unless the whole body condition and
environment can be changed for the better. Consequently individuals
become more and more crippled. Muscle spasm is rarely present,
but when such changes occur in the intervertebral joints the
individual becomes gradually bent over or deformed, partly because
the muscles no longer have strength to maintain the erect posture,
and partly from actual changes in the bones and joints. Most of the
instances, however, are characterized by tenderness, while a
general myalgia or malaise is a frequent complaint. There are
sometimes exacerbations, during which both severe neuralgic pains
and mild fever are quite pronounced. Not infrequently on handling
the affected joint pseudocrepitus or actual crepitus will be obtained.
Sometimes the joint surfaces are roughened, and then this sensation
is most pronounced. When the synovial membrane is proliferated, in
pannus form, over the cartilages, its enlarged fringes will give a soft
crepitus which is quite distinctive. Fragments of these fringes, as well
as of cartilage, may become detached, and loose objects of this kind
in the joint may be recognized by the sense of touch.
While this is going on within the joint, adjoining tendon sheaths
and bursæ become more or less involved, and even the periosteum
will undergo considerable thickening.
The monarticular type is more frequent in men than in women, and
occurs more often in a large joint or in the spine, in which latter case
it is hardly to be considered monarticular. The changes that may
occur in the spine are distinctive, varying from trifling stiffness and
limitation of motion to pronounced deformity, by which, for instance,
not only the kyphosis of acute spondylitis may be imitated, but the
body flexed to an angle with the axis of the pelvis and fixed there, so
that the individual is bent to nearly a right angle. Some of the other
deformities of this condition are more or less characteristic. In the
hands the fingers are bent toward the ulnar side, and often strongly
flexed, perhaps even Fig. 195
overlapped, thus
giving the hand a
peculiar claw-like
appearance. The feet
are extended
completely, the joints
rigid, the toes turned
outward, and also
overlapping. By such
changes in the hip
and knee the legs
and thighs may be
flexed and the hips
perhaps so ankylosed
as to prevent
separation of the
knees. While these
changes are, as
stated, most common
in the later years of
life, children are not
exempt, girls being
more frequently
affected than boys,
the condition coming
on at first with more
or less acute
symptoms. These
children will often be
found to have
enlarged spleens and
lymph nodes, to show
malnutrition, while
some of them will
display certain
symptoms of
exophthalmic goitre.
In other words, they
are in that condition General osteo-arthritis, with multiple synostoses
included under the (“ossified man”).
term status
lymphaticus, to which subject the reader is referred. (See p. 163.)
It would appear, then, that we can expunge the term chronic
articular rheumatism, since by it is not meant the ultimate result of an
acute rheumatic affection, but rather one of the vague conditions
described above.
Fig. 195, taken from a skeleton in the author’s possession,
illustrates an extreme condition of this kind, characterized by multiple
synostoses, nearly all of the principal joints being involved.
As between the terms osteo-arthritis and arthritis deformans it is
not practicable to make such accurate distinctions as shall be
acceptable to all. In a general way the more the bone participates
the more we may use the former designation, whereas when other
joint structures are chiefly involved we may resort to the latter.
In general, then, all these conditions are evidenced by joint
deformity, especially by irregularities, by more or less effusion, by
considerable tenderness, by creaking of the joints when used, by
pain which is a variable feature and may be referred to nerve
disturbances, occasionally by muscle spasm, but always, in cases of
long standing, by muscle atrophy. A view of the interior of joints thus
affected will give a complex picture of atrophy here and hypertrophy
there of each or all of the component structures of the joint,
sometimes with a gradual overgrowth of articular bone surfaces,
sometimes with more or less complete disappearance of the same,
e. g., in the acetabulum.
Treatment.—So far as treatment of these conditions is concerned,
it should be recalled, first of all, that the disease itself is
exceedingly chronic in its tendency, and due to conditions which
have probably been of long standing. Constitutional treatment is as
essential as local, and must consist in restoring the environment and
the nutrition of the patient to normal standards. Elimination is
deficient in such cases, and should be stimulated by hot-air baths,
massage, and such exercise as may be possible, as well as by the
use of diuretics and laxatives to the degree indicated. The local
treatment may consist also of massage, elastic compression,
aspiration in rare instances, the use of wet packs, and, in many
cases, the use of hot, dry air. Various forms of apparatus are now
upon the market by which almost any of the joints may be subjected
to the influence of dry, hot air at a temperature of 280° F. When
properly used, great relief and improvement may be expected. Their
use, however, calls for the best of judgment and a combination of the
measures already mentioned.[31]
[31] The following types of arthritis bear little, if any, relation to true
rheumatic disease, though often spoken of as rheumatoid:
The chronic villous form, most common in the knee, purely local, without
effusion, and giving dry crepitus or creaking. The joint fringes are
numerous, and sometimes vascular. If the crepitus be marked and the
fringes too extensive the latter may be relieved by operation. Otherwise this
form is to be treated by early local stimulation, with some support, at least
with a bandage.
The atrophic form, of unknown etiology, causing progressive and finally
crippling swelling, with later atrophy. There is little if any fluid present. Here
the changes occur in both bone and cartilage, with a tendency to abnormal
calcification. In this form rest and hypernutrition, especially with normal
proteids, are called for, and every possible stimulus to elimination through
all the emunctories.
The hypertrophic arthritis, by which cartilages are first thickened and then
ossified, interfering with motion and with contour. This form causes great
limitation of motion and sometimes pressure on nerves, with referred pains.
It seems to have some relation to cold, exposure, and injury. Detachment of
pieces of cartilage is not uncommon, so that there are loose bodies in the
joint cavity. Treatment here consists of fixation, with improvement of
nutrition and elimination. This form may subside under proper treatment.
The chronic, gouty arthritis, with deposits of sodium urate in and around
the joint tissues, with perhaps some bone absorption beneath them, which
are not connected with the bone. In the digits entire phalanges may
disappear by absorption. The treatment here is essentially constitutional
and directed toward the gouty diathesis.

NEUROPATHIC JOINT DISEASE.


This received its first full and classical description from Charcot in
1868. The term refers to joint lesions which follow and are apparently
connected with certain injuries and diseases of the spinal cord, or
the peripheral nervous system. The non-traumatic forms are mostly
associated with locomotor ataxia and syringomyelia. Some of them
have an abrupt onset, while others come on very insidiously. Pain is
usually notable by its absence, and the involved joints show few, if
any, evidences of hyperemia or inflammation. They become
unnaturally mobile and relaxed and usually much, sometimes
enormously, distended with fluid. The morbid changes within the
joints comprise imaginary combinations of atrophy and hypertrophy,
with proliferative formations in bone cartilages. Osteophytes and
exostoses are met with, and ossification may occur in the
neighboring tendons and ligaments. Surprising alterations take place
in certain joints; thus, as shown in Fig. 197, the head of the humerus
may disappear and corresponding changes may occur in other
joints. While it is the knee which suffers most frequently, no joints,
not even those of the spine or jaw, are exempt.
Fig. 196 Fig. 197

Charcot’s disease of elbow. Atrophic disappearance of bone after


chronic joint disease.

You might also like