Login   Register  
PHP Classes
elePHPant
Icontem

File: schematron_sample.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Luis Argerich  >  Schematron  >  schematron_sample.php  >  Download  
File: schematron_sample.php
Role: ???
Content type: text/plain
Description: An example showing how to use the Schematron class
Class: Schematron
Validate XML files using Schematron from PHP
Author: By
Last change:
Date: 2002-06-19 16:54
Size: 2,107 bytes
 

Contents

Class file image Download
<head>
  <title>Schematron sample</title>
</head>
<?php

  include_once("class_schematron.php");

  print("<h1>Schematron Test</h1>");
  
  $s = new Schematron();
  $s->compile_schematron_from_file("validation_sample1.xml");
  $compiled=$s->get_compiled("validation_sample1.xml");
  $s->save_compiled("validation_sample1.xml","validation1.xsl");
  
  $fp=fopen("validation_sample1.xml","r");
  $uncompiled=fread($fp,filesize("validation_sample1.xml"));
  fclose($fp);
  
  $fp=fopen("sample1.xml","r");
  $xml=fread($fp,filesize("sample1.xml"));
  fclose($fp);
  
  
  /* Uncompiled tests */
  print("<h3>Testing Schematron for uncompiled scripts</h3>");
  
  /* FILE USING FILE */
  $ret=$s->schematron_validate_file_using_file("sample1.xml","validation_sample1.xml");
  print("<textarea rows='10' cols='20'>$ret</textarea>");
  
  /* FILE USING MEM */
  $ret=$s->schematron_validate_file_using_mem("sample1.xml",$uncompiled);
  print("<textarea rows='10' cols='20'>$ret</textarea>");
  
  /* MEM USING FILE */
  $ret=$s->schematron_validate_mem_using_file($xml,"validation_sample1.xml");
  print("<textarea rows='10' cols='20'>$ret</textarea>");
  
   /* MEM USING MEM */
  $ret=$s->schematron_validate_mem_using_mem($xml,$uncompiled);
  print("<textarea rows='10' cols='20'>$ret</textarea>");
  
  /**** COMPILED SCRIPTS **/
  
  print("<h3>Now testing for compiled scripts</h3>");
  /* FILE USING FILE */
  $ret=$s->schematron_validate_file_using_compiled_file("sample1.xml","validation1.xsl");
  print("<textarea rows='10' cols='20'>$ret</textarea>");
  
  /* FILE USING MEM */
  $ret=$s->schematron_validate_file_using_compiled_mem("sample1.xml",$compiled);
  print("<textarea rows='10' cols='20'>$ret</textarea>");
  
  /* MEM USING FILE */
  $ret=$s->schematron_validate_mem_using_compiled_file($xml,"validation1.xsl");
  print("<textarea rows='10' cols='20'>$ret</textarea>");
  
   /* MEM USING MEM */
  $ret=$s->schematron_validate_mem_using_compiled_mem($xml,$compiled);
  print("<textarea rows='10' cols='20'>$ret</textarea>");
  
?>