开发者

Interpret a rule applying multiple xpath queries on multiple XML documents

开发者 https://www.devze.com 2022-12-23 05:39 出处:网络
I need to build a component which would take a few XML documents in input and check the following kind of rules:

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 fal开发者_如何学Cse

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

Thanks


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号