PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » XML » XML_DTD » Bug #168

XML_DTD_Tree->getChildren() underscore problem

Details

Submitted2003-10-30 15:22 UTC
Fromaake at iki dot fi
Assignedcox
StatusClosed
PackageXML_DTD
PHP Version4.3.3
OSMac OS X 10.2.8
Roadmaps(Not assigned)

Comments

[2003-10-30 15:22 UTC] aake at iki dot fi

Description:
------------
It seems that XML_DTD_Tree->getChildren() method fails
to recognize ELEMENT names (in DTD files) with
underscores properly thus interpreting them as two
different elements.

Reproduce code:
---------------
...

$dtd_parser = new XML_DTD_parser();
$dtd_tree = $dtd_parser->parse('book.dtd');
print_r($dtd_tree->getChildren('book'));

...

DTD (book.dtd):

<?xml version="1.0" encoding="UTF-8"?>

<!ELEMENT book (title,author?,page_number)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT page_number (#PCDATA)>

<!ATTLIST book cover (hard | soft | unknown) "unknown">

Expected result:
----------------
Array ( [0] => title [1] => author [2] => page_number )

Actual result:
--------------
Array ( [0] => title [1] => author [2] => page [3] => number )

[2003-12-17 16:23 UTC] i dot veith at gmx dot de

The method "_ELEMENT" splits the Elements and if an Element is Named like "ELEMENT_NAME" The method maks two Elemets out of it ("ELEMENT" and "NAME").
And now its clear, why my xml will never be valide.

What to do:
In the DTD.php (from Package version 0.4.1) on Line 195 and 206 the regular expresion in incomplete.

Line 195:
replace
$children = preg_split('/([^#a-zA-Z0-9.-]+)/', $ch, -1, PREG_SPLIT_NO_EMPTY);
width
$children = preg_split('/([^#a-zA-Z0-9_.-]+)/', $ch, -1, PREG_SPLIT_NO_EMPTY);

line 206:
replace
$reg = preg_replace('/([#a-zA-Z0-9.-]+)/', '(,?\\0)', $reg);
width
$reg = preg_replace('/([#a-zA-Z0-9_.-]+)/', '(,?\\0)', $reg);

It’s the underscore after "0-9" and before ".-".

Compare: (<)D:\www\dtd\DTD.php (12078 bytes)
with: (>)C:\XML_DTD-0.4.1\DTD.php (12462 bytes)

195c194
< $children = preg_split('/([^#a-zA-Z0-9_.-]+)/', $ch, -1, PREG_SPLIT_NO_EMPTY);
---
> $children = preg_split('/([^#a-zA-Z0-9.-]+)/', $ch, -1, PREG_SPLIT_NO_EMPTY);
206c205
< $reg = preg_replace('/([#a-zA-Z0-9_.-]+)/', '(,?\\0)', $reg);
---
> $reg = preg_replace('/([#a-zA-Z0-9.-]+)/', '(,?\\0)', $reg);

[2004-02-18 14:29 UTC] tuupola at php dot net

This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pear.php.net.

In case this was a pear.php.net website problem, the change will show
up on the website in short time.

Thank you for the report, and for helping us make PEAR better.