Other Java XML Notes
The Document building code is not guaranteed to be well behaved in threads. You may very well have many XML files to parse, and you may want to use a thread for each. An implementation of the DocumentBuilderFactory class is not guaranteed to be thread safe. To avoid problems, the application can get a new instance of the DocumentBuilderFactory per thread, and they can be configured differently in terms of how much validation they do, whether they ignore comments and so on.
Here's how we use the Factory instance to get back a Parser that has the type of the abstract class javax.xml.parsers.DocumentBuilder:
... myDb = myDbf.newDocumentBuilder();
Now that we have a DocumentBuilder (which is actually a Pete'sPrettyGoodParser, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access