Saxon SA examples and help wanted for value checking

This should cover W3C XML Schema, Relax NG and DTD related problems.
mlcook
Posts: 67
Joined: Thu Jan 24, 2008 4:52 pm

Saxon SA examples and help wanted for value checking

Post by mlcook »

I would like to start learning and using Saxon SA's ability to do some checking of XML structures, now that Saxon SA is included with Oxygen 10.

I understand that Saxon SA is able to do this kind of processing, including at least basic arithmetic.

If I've been misled, please let me know.

I do have a schema for the structure below, and all the relevant values here have been defined as xs:unsignedInt.

So, given a sample XML structure:

Code: Select all

      <Property>

<Length Value="1150" />

<ItemList NumEntries="4">
<Item Offset="0" Value="12" />
<Item Offset="754" Value="34" />
<Item Offset="935" Value="56" />
<Item Offset="1150" Value="78" />
</ItemList>

<AnotherList NumEntries="1">
<Widget Start="0" End="1150" Value="987" />
</AnotherList >

</Property>

I would like to perform the following kinds of limit/bound checking:

(a) Check that all of the Item Offsets are <= Length's Value.
(b) Check that exactly one of the Offsets of Item = 0.
(c) Check that exactly one of the Offsets of Item = Length's Value.
(The offsets of Item are probably in ascending order, but I'm not
sure I can guarantee that.)
(d) Check that the Start value of Widget is >= 0.
(e) Check that the End value of Widget is <= Length's Value.
(f) Or, instead of (d) and (e), check that Widget's End-Start <= Length's Value.

I would like to do the checking during validation, not at transformation time (since the file gets used elsewhere without being transformed).

Would someone get me started with some examples of how to do the above checks, and point me to some other examples and documentation?

Thanks, Mike
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Saxon SA examples and help wanted for value checking

Post by sorin_ristache »

Hello,

Yes, Saxon SA can be used as an XML Schema validator as other processors like Xerces, XSV, etc. In Oxygen it is available as validator for XML files in the combo box from the toolbar External Validation. Just select Saxon SA in that combo for validating with Saxon SA the current XML file against the XML Schema that the XML file references.

You have to create an XML Schema with the conditions that you enumerated and associate it with the XML file that you want to validate.

For examples about expressing the conditions that you specified in an XML Schema I think you need an XML Schema tutorial, for example this tutorial and this tutorial.


Regards,
Sorin
mlcook
Posts: 67
Joined: Thu Jan 24, 2008 4:52 pm

Re: Saxon SA examples and help wanted for value checking

Post by mlcook »

I looked through the tutorials, and have some experience with schema definitions.

But I must have missed using schemas to check constraints.

I have used uniqueness and key constraints in schemas, but am wanting to do some arithmetic assertions as well.

Thanks for the references.

-- Mike
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Saxon SA examples and help wanted for value checking

Post by sorin_ristache »

Hello,

For this type of constraints you need XML Schema 1.1 assertions or Schematron constraints. XML Schema 1.0 did not allow asertions but in XML Schema 1.1 they are allowed and the Saxon SA validator which is included in Oxygen enforces them in validated XML documents. If you include assertions in an XML Schema 1.1 schema make sure you validate the XML documents by selecting Saxon SA in the combo box of the External Validation toolbar.

If you write an XML Schema 1.0 schema with embedded Schematron constraints make sure that the XSD file is also associated with the XML document also as a Schematron schema with a processing instruction like:

Code: Select all

<?oxygen SCHSchema="path/to/schema.xsd"?>
which is created by the action Associate Schema. Instead of the association made using this processing instruction you can specify the schema type XML Schema + Schematron in a document type that you create and that matches your XML document. In both cases (processing instruction or document type that matches your XML document) the toolbar action Validate Document will validate the XML document against both the XML Schema and the Schematron constraints.


Regards,
Sorin
mlcook
Posts: 67
Joined: Thu Jan 24, 2008 4:52 pm

Re: Saxon SA examples and help wanted for value checking

Post by mlcook »

I tried to add some Saxon SA allowed <xs:assert> checks to validate with Saxon SA, but I got the error that required XML Schema 1.1 to be enabled.

How do I enable XML Schema 1.1?

The initial lines of my XSD file are:

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

etc...

Changing the version above to 1.1 didn't seem to help. So far, I haven't found schema examples using the 1.1 version.

Thanks for any tips.

-- Mike
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: Saxon SA examples and help wanted for value checking

Post by george »

Hi Mike,

That is not possible in 10.0 within oXygen so all you can do is to use Saxon SA as an external engine and enable the option when you configure it - however that will require a Saxon-SA license as the oXygen Saxon-SA license works only when Saxon-SA is used from within oXygen. We already recorded this as it was reported previously, see
http://www.oxygenxml.com/forum/post11048.html
Right now it is scheduled to be solved in 10.2 but we will discuss Monday if we can put it in 10.1 that will be available shortly.

Best Regards,
George
George Cristian Bina
mlcook
Posts: 67
Joined: Thu Jan 24, 2008 4:52 pm

Re: Saxon SA examples and help wanted for value checking

Post by mlcook »

What features of the internal Saxon SA are useful at the moment in Oxygen 10?

If I want to use Saxon SA schema assertions, will I have to wait for Oxygen 10.1 or 10.2?

I suppose Schematron would work, but I'd rather not have to convert later to Saxon.

Thanks, Mike
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: Saxon SA examples and help wanted for value checking

Post by george »

Saxon SA is available in oXygen for XSLT and XQuery execution, debugging and profiling. Also it is available as an XML Schema 1.0 processor.

XML Schema 1.1 is under development right now, Saxon SA offers support for some of the features but note that any of those may be changed in the final 1.1 specification.
I do not see any problem in using Schematron, I would prefer that over XML Schema 1.1.

Best Regards,
George
George Cristian Bina
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Saxon SA examples and help wanted for value checking

Post by sorin_ristache »

Hello,
mlcook wrote:I tried to add some Saxon SA allowed <xs:assert> checks to validate with Saxon SA, but I got the error that required XML Schema 1.1 to be enabled.

How do I enable XML Schema 1.1?
Starting with version 10.1 that will be released in this month you can select between XML Schema 1.0 and XML Schema 1.1 in Preferences / XML / XML Parser / Saxon SA Validation. The preference will be applied to all validations with Saxon SA. We will consider also adding it as an option in a validation scenario.


Regards,
Sorin
gwagner
Posts: 2
Joined: Tue Jun 08, 2010 7:37 pm

Re: Saxon SA examples and help wanted for value checking

Post by gwagner »

Okay, I can use Saxon-EE for XSD 1.1 validation, but I still do get Xerces validation errors.

Is it possible to replace Oxygen's Xerces version by the current trunk version of Xerces for avoiding the nasty Xerces validation errors for assertion elements?
adrian
Posts: 2853
Joined: Tue May 17, 2005 4:01 pm

Re: Saxon SA examples and help wanted for value checking

Post by adrian »

Hi,

I wouldn't recommend replacing Oxygen's Xerces with another version. Oxygen has some internal Xerces patches for various purposes(e.g. for collecting IDs and IDREFs, for correcting URLs) so using a different version could have unpredictable results.

We do plan to offer an option in a future version that will allow to change the default XML schema validator from Xerces to Saxon-EE.

Right now the way to resolve this is to create two custom validation scenarios, one for validating XML Schemas and one for validating XML files. Both validation scenarios should use Saxon-EE. Then these scenarios have to be associated with the corresponding files.

You can create a validation scenario either:
- by opening an XML/XSD file and going to Document -> Validate-> Configure Validation Scenario
- by selecting an XML/XSD file in the Project view, right clicking on it and selecting Configure Validation Scenario

In the Configure Validation Scenario dialog select 'Use custom validation scenario' and click New. Choose a name for the scenario and Add a validation unit.
In the validation unit dialog leave the input URL unchanged(${currentFileURL}) so you can use the scenario for various files, then from the Processor combo select Saxon-EE. OK in all dialogs.

Afterwards you can associate multiple files from the project view with the custom validation scenario you have just configured. You can do this by selecting the XML files in the project view and right clicking and selecting Configure Validation Scenario. Then select the scenario from the list and press OK.

Make sure you give the scenarios distinct names and also make sure that when you associate them it is with the appropriate scenario(XML Schema scenario for XML schemas and XML Document scenario for XML files).

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply