PHP Check XML against online DTD file.

I have an xml file and I would like to check it with DTD.

To do this, I have included a DTD link in XML:

<!DOCTYPE article SYSTEM "http://dtd.nlm.nih.gov/1.1/journalpublishing.dtd">

And then did:

$dom = new DOMDocument();
$dom->loadHTML($xml);

if ($dom->validate()) {
    echo "This document is valid!\n";exit;
}
else {
    var_dump("Not OK");exit;
}

The problem is that I get this warning:

Warning: DOMDocument::validate(http://www.w3.org/TR/REC-html40/loose.dtd): failed to open stream: HTTP request failed! HTTP/1.0 500 Server Error

Any idea? Thank.

+3
source share
1 answer

You are using the wrong method to load XML.

Use loadto load an XML file or loadXML to load an XML string. Use loadHTMLFile to load the HTML file and loadHTML to load the HTML content.

Using one of the HTML methods will invoke the libxml HTML parser module , which

HTML HTML 4.0 API, XML. " " HTML, .

Parser HTML HTML4 Transitional DTD, lenient , , HTML ..

+1

All Articles