Next we merge the two main class programs for the former post into a single application. After execution of this package paths, xml filenames and accompanying content are printed to our NetBeans console.
Earlier I recommended Java beginners to save the main programs in their Hello World project. It’s time to leave this one project approach. As a Java-for-testers beginners you better start a new project for every single problem you encounter. You can always copy the core of your solution to the package where you need it not ‘contaminating’ the project you are actually working on with maybe useless code. Which allows me referring Occam’s razor blade. Today his medieval approach is more useful to us as agile testers in stripping the ‘borrowed’ code than for instance ISQTB. Applying his blade probably gives you the leanest code you need to perform your job. Analysing xml files for example.
You can download the package and import it in NetBeans(Menu: File -> Import Project- > From zip). Hit F6 if the rest is TL;DR to you. Also the package still contains the ReadAndPrintXML.java we used earlier just for comparing purposes. Logs directory containing dummy.xml files too. It was hard for me to come up with catching program, method or variable names so they are a bit extended. Change them as you wish. Depending on what you change, use: Refactor -> rename, just rename or the “replace all” function.
Or the DIY try to figure it out way
- Set up your own NetBeans-project, download the bundled zipped programs: MyXMLHelper.java, FilterLogFiles.java, PrintXMLContentFilteredXMLFiles.java and copy them into your project.
- Create a “logs”-directory yourself in the NetBeans project you are working in. You need to fill this directory with some wellformed xml files.
- Also add the logs directory to your Sources folder in under Project properties settings in the Sources Category(top of menu on the left). I had to change this, maybe you don’t.
- Set the “main” program in project properties under Run Category (In the middle of menu on the left) to readprintxml.MyXMLHelper.
Changes in the package code
Compared to former package the main differences are:
- Some refactoring or renaming of package, classes, file and variable names
- myXMLHelper is the only main application in our project. Not to mention the old ReadAndPrintXMLFile.java in the package of this download version.
- I also removed an exception handler while transferring ReadXMLFiles.java to PrintXMLContentFilteredXMLFiles.
Result or output of package
After you imported the package in your project properties, you can hit F6. Next the content of the xml files is presented in your NetBeans console.