طراحی پورتال های سازمانی شرکت پروجان

شیرپوینت و پراجکت سرور پروجان

استقرار شیرپوینت و پراجکت سرور

مسیر سایت

کتاب Java XML and JSON- Document Processing for Java SE.pdf

Java XML and JSON- Document Processing for Java SE.pdf

دانلود رایگان کتاب Java XML and JSON.pdf 

Document Processing for Java SE

Jeff Friesen

Copyright © 2019 by Jeff Friesen

لینک دانلود کتاب Java XML and JSON- Document Processing for Java SE.pdf

 

Contents

 

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

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

 

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

 

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

 

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

 

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

 

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.
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.

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 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)

  

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 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).

 

لینک دانلود کتاب Java XML and JSON.pdf

 

عضویت در خبرنامه