简体   繁体   中英

Business logic validation with a Java XML parser

We are using JAXB for marshaling and marshaling in our application. The XSD validation is handled by JAXB and the business logic validation is handled by our own code. We are looking to find out a way to handle business logic validation in a configurable way.

For example when an XML file is received by our application, we need to check whether certain entities with their names exist in our database.

Is their any way in JAXB or is their any better API/Parser that can make it more manageable via some kind of configurations? If not, what are the best practices to do these kind of checks?

If you're using an XSD 1.1 processor such as Xerces or Saxon then you could extend the rules in the XSD schema to include business rules, expressed in the form of assertions. However, some people might advise you to keep syntax checking and semantic checking separate, especially if the rules are defined by different people.

An alternative is schematron: many people advocate using XSD for structural validation, followed by schematron processing for checking business rules.

If the expressive power of schematron isn't good enough, then another approach to consider is to continue to write business logic validation in your own code, but to write that code in XSLT, which makes it much more declarative (and therefore easier to change) than writing it in a lower-level language such as Java.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM