XML validation: Difference between revisions

initial submission of php 7.x solution to this problem
(initial submission of php 7.x solution to this problem)
Line 570:
Element 'a': Element content is not allowed, because the type definition is simple.</pre>
 
=={{header|php}}==
<lang php>
libxml_use_internal_errors(true);
 
$xml = new DOMDocument();
$xml->load('shiporder.xml');
 
if (!$xml->schemaValidate('shiporder.xsd')) {
var_dump(libxml_get_errors()); exit;
} else {
echo 'success';
}
</lang>
{{out}}
<pre>
using valid shiporder.xml and shiporder.xsd:
success
Done.
using invalid shiporder.xml and valid shiporder.xsd:
array(1) {
[0] =>
class LibXMLError#2 (6) {
public $level =>
int(2)
public $code =>
int(1871)
public $column =>
int(0)
public $message =>
string(74) "Element 'foo': This element is not expected. Expected is ( orderperson ).
"
public $file =>
string(43) "file:/C:/xampp/htdocs/rosetta/shiporder.xml"
public $line =>
int(4)
}
}
Done.
</pre>
=={{header|Python}}==
 
Anonymous user