Jump to content

Validating xml file


ebryant

Recommended Posts

I have a series of xml files that contain named character entities (for mdashes, and other special characters). The xml file includes a small DTD containing declarations for these entities, but the structure of the xml is defined by an xml schema file (.xsd). How would I go about validating these documents in php5?

 

If I use the schemaValidate, it appears the partial DTD causes errors. If I remove the DTD, the undeclared entities cause an error.

 

Any suggestions?

 

PHP script:

$dom = new DomDocument;
$dom->load($xmlfile);
if ($dom->schemaValidate($xsdfile)) {
  print "$xmlfile is <font color='green'>VALID</font>.\n";
  } else {
  print "<hr/>$xmlfile is <font color='red'>INVALID</font>.\n";
}

 

simplified version of XML file (with DTD entity declaration):

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE case [
<!ENTITY mdash "--">
]>
<case xmlns:case="xxx">
<dockets>
<docnum>05—1789<docnum>
<docnum>05—1790<docnum>
<docnum>05—1791<docnum>
</dockets>
</case>

 

Link to comment
https://forums.phpfreaks.com/topic/45613-validating-xml-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.