Take the 2-minute tour ×

I have a piece of xml that contains optional non-enumerated elements, so schema validation does not catch invalid values. However, this xml is transformed into a different format after validation and is then handed off to a system that tries to store the information in a database. At this point, some of the values that were optional in the previous format are now coded values in the database that will throw foreign key constraint exception if we try and store them. So, I need to build a process in a J2EE app that will check a set of xpaths values against a set of values that are allowable at those spots and if they are not valid either remove them/replace them/remove them and their parents depending on schema restrictions.

I have a couple options that will work, but neither of them seem like very elegant/intuitive solutions.

Option #1 would involve doing the work in an xslt 1.0. Before sending the xml through the xslt, querying up the acceptable values and sending the lists in as parameters. Then place tests at the appropriate locations in the xml that compares the incoming value against the acceptable ones and generates the xml accordingly.

This option doesn't seem very reusable, but it'd be very quick to implement.

Option #2 would involve Java code and an xml config file. The xml config file would layout the xpaths of the needed tests, the acceptable values, the default values (if applicable) and what to take out of the doc if the tests fail.

This option is much more reusable, but would probably double the time needed to build it.

So, which one of these would you pick? Or do you have another idea altogether? I'm open to all suggestions and would love to hear how you would handle this.

share|improve this question
What's not "reusable" in #1 compared to #2? It will effectively mean that XSLT file is your config, and script-based configs are always more flexible. –  Pavel Minaev Sep 9 '09 at 23:18

3 Answers 3

up vote 1 down vote accepted

Sounds to me like option 2 is over-engineering. Do you have a clear idea about when you will want to reuse this functionality? If not, YAGNI, so go for the simpler and easier solution

share|improve this answer

Both options are acceptable. Depending on your skills and the complexity of your XML, I would say that it will require about the same amount of time.

  • Option 1 would be in my opinion more flexible, easier to maintain in the long run.

  • Option 2 could be tricky in some cases, how to define the config file itself for complex rules and how do you parse it without having to write complex code? One could say, I'll use a dom4j visitor and I'll be done with it. However, option 2 could become unnecessarily complicated imho if you deal with a complex XML structure.

share|improve this answer

I agree here. It felt like it was borderline over-engineering, but I was afraid that someone hearing that this was done would assume that it would be reusable and attempt to design something that used it in the future. However, I have since been reassured that this is a one-time deal and thus, will be going with the xslt approach.

Thanks all for your comments/answers!

share|improve this answer
Hi! Answers are not the right place to comment other answers here. Comments under answers or modification of your question is. –  dzieciou Sep 19 '12 at 18:17

Your Answer


