note 41814 deleted from function.xml-parse by didou
| From: | didou@php.net | Date: | Thu, 03 Feb 2005 19:50:17 +0000 |
| Subject: | note 41814 deleted from function.xml-parse by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-84470@lists.php.net to get a copy of this message | ||
Note Submitter: sfarrell at webmd dot net
----
The XML specifications (1.0, third edition) allow the use of several special characters in XML tags;
namely, the period (.), dash (-), and colon (:) which cannot be used within a PHP object or variable
name. As such, the XmlC class breaks during the eval() statement when the XML document contains
tags using one or more of these characters. You can prevent this by modifying the _startElement()
function (adding the preg_replace() statement) to read as follows:
<?php
function _startElement( $parser, $tag, $attributeList )
{
foreach( $attributeList as $name => $value )
{
$value = $this->_cleanString( $value );
$object->$name = $value;
}
$tag = preg_replace("/[:\-\. ]/", "_", $tag);
eval( "\$this->pointer[\$this->index]->" . $tag . "[] =
\$object;" );
eval( "\$size = sizeof( \$this->pointer[\$this->index]->" . $tag . "
);" );
eval( "\$this->pointer[] = &\$this->pointer[\$this->index]->" .
$tag . "[\$size-1];" );
?>
This simply replaces the special characters with the underscore (_) character which IS allowed in
object/variable names. If you'd prefer a different character or no character to be used,
modify the preg_replace() statement appropriately. Hope the info helps.