To my parents.
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)
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.
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.
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 ).
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).
3.128.78.30