Read XML Xalan Java
Xalan is very popular library from Apache which implements XSLT XML transformation language and XPath language. Reading XML file using is faster where you could use Xpath to read the file.
If you are building new application and want to keep configuration related information in one central location, many choices are available out of which keeping information on XML file can be good choice and this will work as central location of all configuration where you can divide XML config file based on the environment. We will use Xalan parser to read XML file. Below is sample XML file which is divided in two environment i.e DEV and QA. I will create small project to show you how to load and read XML file where static block will be use load XML file first time when user makes call and keep data in cache to give better performance in web application.
- Sample maven project structure:
- Sample xml file: XMLBootstrap.xml
- XMLConfig.java: To parse XML file:
- Client class which will call XMLConfig.java and read its value:
- For more details on Xalan please please go here
Download Project: ReadXMLConfig