Java Reference
In-Depth Information
CHAPTER 20
XML Processing
XML APIs have always been available to the Java developer, usually supplied as third-
party libraries that could be added to the runtime class path. Beginning in Java 7, the
Java API for XML Processing (JAXP), Java API for XML Binding (JAXB), and the
Java API for XML Web Services (JAX-WS) were included in the core runtime libraries.
The most fundamental XML processing tasks that you will encounter involve only a few
use cases: writing and reading XML documents, validating those documents, and using
JAXB to assist in marshalling/unmarshalling Java objects. This chapter provides recipes
for these common tasks.
Note The source code for this chapter's examples is available in the
org.java8recipes.chapter20 package. See the introductory chapters for in-
structions on how to find and download this topic's sample source code.
20-1. Writing an XML File
Problem
You want to create an XML document to store application data.
Solution
To write an XML document, use the javax.xml.stream.XMLStreamWriter
class. The following code iterates over an array of Patient objects and writes the data
Search WWH ::




Custom Search