0

i have to implement schematron validation for my xml(xbrl) files.i have searched and tried some libraries such as NMatrix and Saxon based on msdn.

http://msdn.microsoft.com/en-us/library/aa468554.aspx

-NMatrix schematron validation not validate my xml i mean it is not giving any exception. -Saxon free edition is not validate xml through sch files.

My question is how can i implement xml validation based on schematron rules. I have also open advices for other languages java,php.

Thanks for your help.

4 Answers4

1

There are some XSLT Stylesheets that you can use to validate XML documents against an Schematron schema. You could use them with the XSLtransform class and look at the resulting document.

The official stylesheet for version 1.5 can be found here

You can also take a look to Probatron I have never used it, but its website states that it's a .net validator for schematron.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Bill Velasquez
  • 875
  • 4
  • 9
0

I could not find enough sample code for Schematron validation in .Net so I started to code my own validation like this.

I have XBRL based XML document and also SCH file for validation rules. I am using Gepsio library for parsing XBRL documents.

public bool IsDocumentInfoExists(XbrlDocument xbrlDoc)
    {

        foreach (var currentFragment in xbrlDoc.XbrlFragments)
        {
            foreach (var cnodes in currentFragment.XbrlRootNode.ChildNodes)
            {
                if (!cnodes.GetType().Name.Contains("XmlComment"))
                {
                    var glcorAccountingEntries = ((XmlElement)(cnodes));

                    if (glcorAccountingEntries.Name.Equals("gl-cor:accountingEntries"))
                    {
                        foreach (var glcorAccountingEntry in glcorAccountingEntries)
                        {
                            if (!glcorAccountingEntry.GetType().Name.Contains("XmlComment"))
                            {
                                var documentInfo = ((XmlElement)(glcorAccountingEntry));
                                if (documentInfo.Name.Equals("gl-cor:documentInfo"))
                                {
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
        }
        return false;
    }
Piotr Kula
  • 9,597
  • 8
  • 59
  • 85
0

I needed the same thing and I investigated it further and found Schematron.NET

Download the file, it has a basic win forms validator or just open the DLL project on its own, read the source if you want, compile the DLL and embed it in your project.

Then in the schema you declare it like this.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.com/po-schematron" xmlns="http://example.com/po-schematron" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xsd:annotation>
    <xsd:appinfo>
      <schema xmlns="http://www.ascc.net/xml/schematron">

Lastly, you just need to spend some time and read the Schematron ISO and get on with validating XML.. even though you know you don't really want to.. but sometimes you just have to.

Piotr Kula
  • 9,597
  • 8
  • 59
  • 85
0

I implemented my own validation using the Saxon xslt engine.

I basically created a Transformer class to wrap a Saxon.Api.Processor and listen to the messages emitted from it, via the IMEssageListener interface.

Then a SchematronValidator class that took the schematron sheet and then passed it through the schematron file iso_dsdl_include.xsl, then the output through iso_abstract_expand.xsl, and that output through iso_svrl_for_xslt2.xsl, which finally gave me the validating sheet.

I then had to write some parsing logic to go through the validation output and collect up all the assertions, etc.

Andrew
  • 121
  • 4