tags:

views:

40

answers:

2

For example,

Xml document:

<some_document>
 <elements>
  <element>1</element>
  <element>2</element>
  <element>3</element>
 </elements>
 <sum>6</sum>
<some_document>

Rules(in some form, probably in xml), according to schema of given document:

Sum of all <element> fields must match the value in <sum> field

Result: Is document valid, according to rules specified or not?(in xml form too, probably)

So, I need a library that implements given functionality or at least points to dig in for writing one by myself. Language does not matter.

A: 

You could use xslt to add the values of <element> tags and compare to the value in <sum>

<xsl:value-of select='sum(//element) = //sum'/>

this will return the comparison result..

Gaby
There will be some tricky rules, and xslt does not cover all the issues. So, I need more generic solution.
Yuri
+1  A: 

Schematron would probably be a good solution.

Schematron is an ISO standard and provides a way of encoding business rules, restrictions and validation that is not possible in XML Schema. The rules are comiled into XSLT and can run in any environment that can invoke XSLT transformations.

The Schematron differs in basic concept from other schema languages in that it not based on grammars but on finding tree patterns in the parsed document. This approach allows many kinds of structures to be represented which are inconvenient and difficult in grammar-based schema languages. If you know XPath or the XSLT expression language, you can start to use The Schematron immediately.

Mads Hansen
Schematron rules are too static. For, example, I need to specify rule where the currency rate in some field must match the currency rate for the specified period of time. Currency rates should be stored in the database, and when I fire up verification I need to check out the database result about currency rate for a given date. Is it possible with schematron? So, I think, I need more like a helper library, than a complete solution.
Yuri