Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

DOMDocument->relaxNGValidateSource()

(no version information, might be only in CVS)

DOMDocument->relaxNGValidateSource() --  Performs relaxNG validation on the document

Описание

class DOMDocument {

bool relaxNGValidateSource ( string source )

}

Performs relaxNG validation on the document based on the given RNG source.

Список параметров

source

A string containing the RNG schema.

Возвращаемые значения

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.



add a note add a note User Contributed Notes
DOMDocument->relaxNGValidateSource()
gem at rellim dot com
12-Oct-2004 04:47
Took me a while to get a working example.  Here it is:

<?php

# enable warnings
ini_set( 'track_errors', 1);
ini_set('error_reporting', E_ALL | E_STRICT);

# this is a sample relaxNG definition
$rng = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0"
  datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <start>
    <element name="apple">
      <element name="pear">
        <data type="NCName"/>
      </element>
    </element>
  </start>
</grammar>
EOT;

# well formed xml, but invalid per schema
# too many pears
$bad_xml =<<<EOT
<?xml version="1.0"?>
<apple>
  <pear>Pear</pear>
  <pear>Pear</pear>
</apple>
EOT;

# well formed xml and valid per schema
$good_xml =<<<EOT
<?xml version="1.0"?>
<apple>
  <pear>Pear</pear>
</apple>
EOT;

# this function does the work, it tests the relaxNG in the string $rng
# against the xml in string $xml
Function relaxNG ( $xml, $rng ) {
       
$dom_xml = new DomDocument;
       
$dom_xml->loadXML($xml);
                       
        if (
$dom_xml->relaxNGValidateSource ( $rng ) ) {
                echo
"Good\n";
        } else {
                echo
$php_errormsg . "\n";
        }
}      

# test the good xml, will echo:
#    Good
relaxNG ($good_xml, $rng);
                       
# test the bad xml, will echo:
#    Did not expect element pear there
relaxNG ($bad_xml, $rng);

?>

results:

Good
Did not expect element pear there

DOMDocument->save()> <DOMDocument->relaxNGValidate()
Last updated: Fri, 26 Jan 2007
 
 
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571