Re: [PHP-XML-DEV] DTD validation problem

[email protected] (Rob Richards) Wed, 23 Feb 2005 17:40:04 -0500
Newsgroups php.xml.dev
Message-ID <[email protected]>
Try using xml_parser_create_ns when you create your parser. SAX 2 is 
required for that default attributes to work and the only way to enable 
SAX2 support under libxml in the xml extension is to create the parser 
with namespace support.
Rob

Mike Phillipson wrote:

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