Input Validation in XMLToCSVBasic.java

JAXP performs validation in the DocumentBuilder's parse method. There is no special “validate” method as such. We tell JAXP that we want validation by specifying the type of DocumentBuilder the DocumentBuilderFactory should make. This is kind of like knowing that you want to build a barbecue out of titanium instead of stainless steel and calling the toolmaker to have him make tools to work with the former rather than the latter.

So, what options do we want to set on the DocumentBuilderFactory? Aside from the obvious one of telling it we want to validate, there are a few others. Here's the relevant code added to XMLToCSVBasic.java.

Validation Code in XMLToCSVBasic.java
 // Set up DOM XML environment DocumentBuilderFactory ...

Get Using XML with Legacy Business Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.