Bug #10994: DOMXML CDATA Node Bug
| From: | dennis at svitonline dot com | Date: | Mon, 21 May 2001 11:49:13 +0000 |
| Subject: | Bug #10994: DOMXML CDATA Node Bug | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-56031@lists.php.net to get a copy of this message | ||
From: dennis@svitonline.com
Operating system: Winnt
PHP version: 4.0.5
PHP Bug Type: *XML functions
Bug description: DOMXML CDATA Node Bug
Hello Dear PHP Support.
I have compatability problem with PHP 4.04 - PHP 4.05, exactly in DOMXML (i mean) module.
This is piece of my code:
-------------------------------------------------------------
<?
function XML_Def_Parse($xml_file) {
$doc = xmldoc(join("", file($xml_file)) );
$ctx = xpath_new_context($doc );
//
$doc_vars = xml_parse_vars($ctx, "//DOC/VAR");
$obj = xpath_eval($ctx, "//DOC/BLOCKS/BLOCK");
$arr = $obj->nodeset;
for($block_n=1; $block_n<sizeof($arr)+1; ++$block_n) {
$block_vars = xml_parse_vars($ctx, "//DOC/BLOCKS/BLOCK[$block_n]/VAR");
$obj2 = xpath_eval($ctx, "//DOC/BLOCKS/BLOCK[$block_n]/BLOCKSET");
$arr2 = $obj2->nodeset;
for($blockset_n=1; $blockset_n<sizeof($arr2)+1; ++$blockset_n) {
$myobj = xpath_eval($ctx, "//DOC/BLOCKS/BLOCK[$block_n]/BLOCKSET[$blockset_n]");
$myarr = $myobj->nodeset;
$blockset_type = $myarr[0]->getattr("type");
//
$obj3 = xpath_eval($ctx,
"//DOC/BLOCKS/BLOCK[$block_n]/BLOCKSET[$blockset_n]/BLOCKSETELEMENT");
$arr3 = $obj3->nodeset;
$blocksetelements = array();
for($blocksetelement_n=1; $blocksetelement_n<sizeof($arr3)+1; ++$blocksetelement_n) {
$blocksetelement_vars = xml_parse_vars($ctx,
"//DOC/BLOCKS/BLOCK[$block_n]/BLOCKSET[$blockset_n]/BLOCKSETELEMENT[$blocksetelement_n]/VAR");
$blocksetelements[] = $blocksetelement_vars;
}
//$blocksets[$blockset_type] =
array(array("sa"=>"as"),array("s2"=>"a2"));
$blocksets[$blockset_type] = $blocksetelements;
}
$blocks[] = array_merge($block_vars, $blocksets);
}
$blocks_arr = array("BLOCKS"=>$blocks);
$doc_v = array_merge($doc_vars, $blocks_arr);
}
function xml_parse_vars($ctx,$path) {
$obj = xpath_eval($ctx, $path);
$arr = $obj->nodeset;
if($path == "//DOC/BLOCKS/BLOCK[1]/BLOCKSET[2]/BLOCKSETELEMENT[1]/VAR") {
print_r($arr);
}
for($x=0; $x<sizeof($arr); ++$x) {
$name = $arr[$x]->getattr("name");
$value = $arr[$x]->content;
$results[$name] = $value;
}
return $results;
} //function
XML_Def_Parse("kulichki.xml");
?>
-------------------------------------------------------
This is "kulichki.xml":
------------------------------------------------------
<?xml version="1.0"?>
<DOC version="1.0" copyright="(c) Denis Torbichuk, 2000">
<VAR name="DOC_CODE">KULICHKI.TV</VAR>
<VAR name="DOC_DESC">Ïðîãðàììà òåëåïåðåäà÷ íà
Kulichki</VAR>
<VAR name="DOC_URL">tv6.htm</VAR>
<BLOCKS>
<BLOCK number="1">
<VAR name="BLOCK_DESC">Îáùèé áëîê</VAR>
<VAR name="BLOCK_BEGIN"></VAR>
<VAR name="BLOCK_END"></VAR>
<BLOCKSET type="SINGLE">
</BLOCKSET>
<BLOCKSET type="MULTIPLE">
<BLOCKSETELEMENT>
<!--
<P><FONT SIZE=+2><B>Ïîíåäåëüíèê. 09 Àïðåëÿ. 41
ÊÀÍÀË<br></B></FONT><HR>
-->
<VAR name="EL_DESC">Êàíàë/äåíü</VAR>
<VAR name="EL_PATTERN_BEGIN"/>
<VAR name="EL_PATTERN"><![CDATA[<P>.*?<FONT.*?><B>{%%:day}.
{%%:day} {%%:month}.
{%%:channel}<br>.*?<HR>.*?<pre>{%%:programs}</pre>]]></VAR>
<VAR name="EL_PATTERN_END"/>
</BLOCKSETELEMENT>
</BLOCKSET>
</BLOCK>
</BLOCKS>
</DOC>
-----------------------------------------------------
This script output in PHP 4.04 (it is right):
X-Powered-By: PHP/4.0.4
Content-type: text/html
Array
(
[0] => DomNode Object
(
[type] => 1
[name] => VAR
[content] => Êàíàë/äåíü
[node] => Resource id #24
)
[1] => DomNode Object
(
[type] => 1
[name] => VAR
[node] => Resource id #25
)
[2] => DomNode Object
(
[type] => 1
[name] => VAR
[content] => <P>.*?<FONT.*?><B>{%%:day}. {%%:day} {%%:month}.
{%%:channel}<br>.*?<HR>.*?<pre>{%%:programs}</pre>
[node] => Resource id #26
)
[3] => DomNode Object
(
[type] => 1
[name] => VAR
[node] => Resource id #27
)
)
But this is output from PHP 4.05 (it is wrong):
X-Powered-By: PHP/4.0.5
Content-type: text/html
Array
(
[0] => DomNode Object
(
[type] => 1
[name] => VAR
[content] => Êàíàë/äåíü
[node] => Resource id #24
)
[1] => DomNode Object
(
[type] => 1
[name] => VAR
[content] =>
[node] => Resource id #25
)
[2] => DomNode Object
(
[type] => 1
[name] => VAR
[content] =>
[node] => Resource id #26
)
[3] => DomNode Object
(
[type] => 1
[name] => VAR
[content] =>
[node] => Resource id #27
)
)
-----
As you see my CDATA node content is empty in PHP 4.05 case.
Why? It is bug?
When I insert text in node instead CDATA it is works.
Can you explain me problem?
P.S. I'm using PHP 4.04 & PHP 4.05 on WinNT (W2k) platform.
Thanks.
Sincerely yours,
Denis Torbichuk.
dennis@svitonline.com
--
Edit Bug report at: http://bugs.php.net/?id=10994&edit=1