Jeff Friesen
Java XML and JSONDocument Processing for Java SE2nd ed.
Jeff Friesen
Dauphin, MB, Canada
ISBN 978-1-4842-4329-9e-ISBN 978-1-4842-4330-5
Library of Congress Control Number: 2018968598
© Jeff Friesen 2019
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.
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 [email protected], 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.

To my parents.

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.

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.

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.

Table of Contents

Part I: Exploring XML1
Part II: Exploring JSON185
Index 519

About the Author and About the Technical Reviewer

About the Author

Jeff Friesen
../images/394211_2_En_BookFrontmatter_Figb_HTML.jpg

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

 

About the Technical Reviewer

Massimo Nardone
../images/394211_2_En_BookFrontmatter_Figc_HTML.jpg

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

 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.78.30