Solution for semantic control of xml document
For example,
Xml document:
<some_document>
<elements>
<element>1</element>
<element>开发者_JS百科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.
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.
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..
精彩评论