Validation using schematron?

M

Marco Cyriacks

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dear all,

within a C++ application I use xerces-c to validate XML instances
against a XML schema. This works very fine for me but currently I try to
realise the validation of some inner restricting for those XML
instances. Some examples:


1. If element 'PluginDescription' has the optional attribute 'attrPD'
and this attribute is true, the child element 'Resources' has to have
exactly one child element 'Resource' with an attribute 'attrR="AAA"'
(check against existence and value of that attribute).

<PluginDescription attrPD="true">
<Resources>
<Resource attrR="AAA"/>
</Resources>
</PluginDescription>


2. If element 'PluginDescription' does not have the optional attribute
'attrPD' or this attribute is false, the contents and number of child
elements for 'Resources' is arbitrarily.

<PluginDescription attrPD="false">
<Resources>
<Resource attrR="AAA"/>
<Resource attrR="BBB"/>
</Resources>
</PluginDescription>

<PluginDescription>
<Resources>
<Resource attrR="AAA"/>
</Resources>
</PluginDescription>

<PluginDescription>
<Resources>
</Resources>
</PluginDescription>


Is it possible to validate a XML instance against these restrictions? If
I'm right, it is not possible to do this using XML schema.

My ideas on it:

- - Implementation of the validation against those restrictions in my
application using C++ and xerces-c

This might by the easiest solution but will force application change
and recompilation if the restrictions change.

- - Creation of schematron

During a web research I found informations on XML schematron.
Unfortunately my first trials on that failed. Is it possible to validate
my XML instances against the presented restrictions using schematron?


Any help would be appreciated!


Best regards,
Marco
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJL4+apAAoJEH1rHVTBeH9oYGcH/jbmoVp/rVN597msIuFSjFiJ
6TSgictCzEm0M9Bb9pytmPhXHV20XH8i9SkzZSTzSk+nkZTqCxLyBoOyAFOITAbT
k1fktn2UYMtlFKNg8Z8hgdk2CiAVDR0qIVr6rzJ3xpcXndrLdagSo4nsnC5YAVV6
aMCBhv8hGcSz23p6K02c0TddpqLv7VO1cQRPXNkKVESXSiCJ5n/3Lx1kzZP6Z9BS
oEJ6o+vB933jkcoyuKUAwhaGp81G0DOCX7s5wJ0HT6EufCqtdumRsZB7sRWYucBC
HXbc3bRWAxEfDstNrtPkJFRwFK6Xc4eEmGb0kEMORY8fy5ttqigpTHOb7S3p6cc=
=gBop
-----END PGP SIGNATURE-----
 
S

Susanne Wunsch

Hello Marco,

Marco Cyriacks said:
Is it possible to validate a XML instance against these restrictions? If
I'm right, it is not possible to do this using XML schema.

Yes, no co-constraints can be implemented in XML Schema 1.0. You may
have a look at XML Schema 1.1, it is enhanced with schematron-like
asssertions.
- Creation of schematron

During a web research I found informations on XML schematron.
Unfortunately my first trials on that failed.

Sorry, I can't help with the current files. My Saxon isn't that new.

I use a slightly older version of the public XSLT scripts (by December
15th, 2009) that work out of the box.

You could post your Schematron file and the according XML file in order
to check the syntax.
Is it possible to validate my XML instances against the presented
restrictions using schematron?

Of course, your constraints are a nice task for Schematron.

read you ...
Susanne
 
M

Marco Cyriacks

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Susanne,

thanks for your reply!

Yes, no co-constraints can be implemented in XML Schema 1.0. You may
have a look at XML Schema 1.1, it is enhanced with schematron-like
asssertions.

I did a short web search on that but I think that Xerces-C (the XML
parser I use) is not yet able to handle XML schema 1.1, at least the
version of xerces-c that is distributed with my operating system
(xerces-c-2.8.0).

Sorry, I can't help with the current files. My Saxon isn't that new.

Currently and only for testing I use xsltproc
(http://xmlsoft.org/XSLT/xsltproc2.html) that is only able to handle
XSLT 1.0 therefore I took the reference implementation of schematron from

http://www.schematron.com/tmp/iso-schematron-xslt1.zip

This might be the same you use...?

You could post your Schematron file and the according XML file in order
to check the syntax.

Obviously I had some syntax problems in my quick'n'dirty schematron.
This afternoon I tried to check the example on

http://www.zvon.org/xxl/SchematronTutorial/Examples/Example1/example.html

I was able to validate that example using the following script:

- ------------------------------------------------------
#!/bin/bash

echo Step1 ...
xsltproc iso_dsdl_include.xsl $1 > step1.xsl

echo Step2 ...
xsltproc iso_abstract_expand.xsl step1.xsl > step2.xsl

echo Step3 ...
xsltproc iso_svrl_for_xslt1.xsl step2.xsl > step3.xsl

echo Validation ...
xsltproc step3.xsl $2 > result.svrl
- ------------------------------------------------------

Everything went fine and I got the expected result.

Now I have to figure out how to create the correct schematron for my
problem... ok, there are still some hours left today :)


Best regards,
Marco
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJL5ENsAAoJEH1rHVTBeH9oIyMH/RdgWi0hJKM1xZwSMKgrpkKt
DcvJ1ul9yOku5o0k6zA2ivNMmnYngyHhwHfmjyB+eQDzbBUQpnJ8EFy1ahGHKu59
aU77AfpzazQQQT+eEt7x70q+esHPyqkR53y9mR0CKsL39CMtUGNxDWZTum+a+CSW
jaQHFtu1nAm8aBkDn6G+st+kiJTn2b6qqFTM745h3xoKp+KYZs76lzNEEb/lcMpG
rxmiJx+tAbOZdnNiy9RntbVXf19Zt0mFWd9PU+B54P5zEds1XkJWI9NCEo0s0Vs9
zVa03ub9SPUW8iwmCd5Gkh2BnElAyjqd5xF/ZV9AJNCyOy2mGEnvuVLS2NkG5j4=
=TPzw
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top