Yury Kaspiarovich
Yury Kaspiarovich

Reputation: 2137

Solution for semantic control of xml document

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.

Upvotes: 1

Views: 117

Answers (2)

Mads Hansen
Mads Hansen

Reputation: 66783

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.

Upvotes: 1

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196177

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..

Upvotes: 0

Related Questions