DTD validation problem

From: Date: Wed, 23 Feb 2005 20:24:51 +0000
Subject: DTD validation problem
Groups: php.xml.dev 
Request: Send a blank email to php-xml-dev+get-543@lists.php.net to get a copy of this message
We parse our XML using the PHP SAX functions (e.g., xml_parse(), etc.). The XML we receive might take the form: <USERDATA> <YOURNAME>Will Smith</YOURNAME> . . </USERDATA> Before we pass this data to our parser, we prepend a string representing the DTD we use to validate the data. Based on my example data, the corresponding DTD would take the form: <?xml version="1.0"?> <!DOCTYPE USERDATA [ <!ELEMENT USERDATA (YOURNAME, ...)> <!ELEMENT YOURNAME (#PCDATA)> . . <!ATTLIST YOURNAME maxlength CDATA #FIXED "40"> . . ]> Note that we are defining an attribute called "maxlength" with a default ("FIXED") value of "40". When the combined string containing the DTD and the XML data is parsed, we check that the value of YOURNAME does not exceed the predefined number of characters. If it does, we return an error. Under PHP 4, xml_parse() reads the data above and populates the attributes array for YOURNAME just as it would if the user had passed: <YOURNAME maxlength="40">Will Smith</YOURNAME> Under PHP 5, however, xml_parse() appears to ignore default attributes altogether. As a result, the attributes array for YOURNAME is empty. This is a big problem for us because our method of validation is essentially defeated under PHP 5. I assume this difference in behavior between PHP 4 and 5 can be ascribed to the differences between the expat and libxml2 libraries in each version respectively. That having been said, we are considering migrating to PHP 5 for various reasons, but before we do, we need to know if there is a way to force our SAX parser to recognize default attributes under PHP 5. Any help is very much appreciated!

« previous php.xml.dev (#543) next »