My requirement is that I have a number of XML templates and depending on certain decision params, I have to populate it either with values given by user or from a property file. The XMLs are quite long and nested. I understand any of the following approaches need to be taken for the solution:
1). First unmarshall the xml into a java object >> populate the object from user/property file >> again marshall the resulting object to get the final xml. 2). search for the pattern of tags and replace it with the given values.
I believe former approach is better since it Object oriented and less errorneous, though it will be a big task to populate each and every instance variable of the object.
Also that the latter may result in a cumbersome code as well as lots of errors as pattern may be different : for e.g.,
> <maven></maven>
or <maven />.
My question is, is there any other promising and faster approach that can be taken to achieve this?
Any help will be highly appreciated.
You might use xpath for extracting xml tags.
How to read XML using XPath in Java
Also it should be tried to see if it is faster.