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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.