[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Validate xml against dtd in php


Subject: [xsl] Validate xml against dtd in php
From: "Kjellaug Johansen" <kjellaug.johansen@xxxxx>
Date: Tue, 9 Sep 2008 11:39:29 +0200

Hi.

I want to validate my xml against a dtd located on the disc. Even if I
try to validate xml I know are valid (I've tried to validate it against
the dtd in xmlspy aswell), the result always prints 'Not valid'. Anyone
who knows how I can do this?

<?php

function validate($xmlstring) {
	$dtd = "mydtd.dtd";
	$dom = new domDocument;
	$dom->loadXML($xmlstring);
	if (!$dom->validate($dtd))
	  print "Not valid\n";
	else
	  print "Valid\n";
}

validate("<book><test>hello</test></book>");

?>

Thanks!

Kjellaug.


Current Thread
Keywords
xml