Question

I need to build a component which would take a few XML documents in input and check the following kind of rules:

XML1:/bookstore/book[price>35.00] != null 
and (XML2:/city/name = 'Montreal'
     or XML3://customer[@language] contains 'en')

Basically my component should be able to:

  • substitute the XML tokens with the corresponding XML document(before colon)
  • apply xpath query on this XML document
  • check the xpath output against expected result ("=", "!=", "contains")
  • follow the basic syntax ("and", "or" and parentheses)
  • tell if the rule is true or false

Do you know any library which could help me? maybe JavaCC?

Thanks

Was it helpful?

Solution 2

Somebody on the JavaCC mailing list pointed me to the right direction, mentioning Schematron. It led me to Probatron which seems to be the best java implementation available.

Schematron web site claims that the language supports "jump across links and between XML documents to check constraints" but it seems Probatron doesn't allow that. I may not to tweak it or find a trick for that (like building a temporary XML document containing all my source documents). Apart from that, it looks Probatron is the right library for me.

OTHER TIPS

For evaluating XPATHs I recommend JAXEN.

Jaxen is an open source XPath library written in Java. It is adaptable to many different object models, including DOM, XOM, dom4j, and JDOM. Is it also possible to write adapters that treat non-XML trees such as compiled Java byte code or Java beans as XML, thus enabling you to query these trees with XPath too.

The Java XPath API (Java 5 / javax.xml.xpath) is also an option, but I haven't tried it yet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top