note 45725 added to function.xml-parse
| From: | petrek at KMLinux dot fjfi dot cvut dot cz | Date: | Thu, 16 Sep 2004 11:10:22 +0000 |
| Subject: | note 45725 added to function.xml-parse | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76818@lists.php.net to get a copy of this message | ||
I've add some functions (selectSingleNode, selectNodes)
that can be useful for some basic operations
can be found here http://bimbo.fjfi.cvut.cz/~petrek/objxml.php
<?
function selectSingleNode($xpath)
{
$arrPath=split("/",$xpath);
$larrPath=count($arrPath);
$elem=array();
$cond=array();
for ($q=0;$q<$larrPath;$q++)
{
$str=preg_split("/[\[\]]/",$arrPath[$q]);
$elem[$q]=$str[0];
$test=$str[1];
if ($test)
{
$test=preg_replace("/([^@])and/","$1&&",$test);
$test=preg_replace("/([^@])or/","$1||",$test);
$re="/(@([a-zA-Z0-9]+))/";
do {
$oldtest=$test;
$test=preg_replace($re,"\$nd->getAttribute('$2')",$oldtest);
} while ($test!=$oldtest);
$test=preg_replace("/@/","",$test);
$test=preg_replace("/!=/","!@#",$test);
$test=preg_replace("/=/","==",$test);
$test=preg_replace("/!@#/","!=",$test);
$cond[$q]=$test.";";
} else
$cond[$q]=0;
// echo ($elem[$q].": ".$cond[$q]."<BR>");
}
$nodes = array($this);
for ($i=0;$i<$larrPath-1;$i++)
{
$nl=count($nodes);
$nodes1 = array();
for ($n=0;$n<$nl;$n++)
{
$nodes2=$nodes[$n]->SN($elem[$i],$cond[$i]);
$y=count($nodes1);
for ($x=0;$x<count($nodes2);$x++)
$nodes1[$x+$y]=$nodes2[$x];
}
$nodes=$nodes1;
}
$nl=count($nodes);
for ($n=0;$n<$nl;$n++)
{
$node=$nodes[$n]->SSN($elem[$i],$cond[$i]);
if ($node) return $node;
}
}
function selectNodes($xpath)
{
$arrPath=split("/",$xpath);
$larrPath=count($arrPath);
$elem=array();
$cond=array();
for ($q=0;$q<$larrPath;$q++)
{
$str=preg_split("/[\[\]]/",$arrPath[$q]);
$elem[$q]=$str[0];
$test=$str[1];
// echo ($elem[$q].": ".$test."<HR>");
if ($test)
{
$test=preg_replace("/([^@])and/","$1&&",$test);
$test=preg_replace("/([^@])or/","$1||",$test);
$re="/(@([a-zA-Z0-9]+))/";
do {
$oldtest=$test;
$test=preg_replace($re,"\$nd->getAttribute('$2')",$oldtest);
} while ($test!=$oldtest);
$test=preg_replace("/@/","",$test);
$test=preg_replace("/!=/","!@#",$test);
$test=preg_replace("/=/","==",$test);
$test=preg_replace("/!@#/","!=",$test);
$cond[$q]=$test.";";
} else
$cond[$q]=0;
// echo ($elem[$q].": ".$cond[$q]."<BR>");
}
$nodes = array($this);
for ($i=0;$i<$larrPath;$i++)
{
$nl=count($nodes);
$nodes1 = array();
for ($n=0;$n<$nl;$n++)
{
$nodes2=$nodes[$n]->SN($elem[$i],$cond[$i]);
$y=count($nodes1);
for ($x=0;$x<count($nodes2);$x++)
$nodes1[$x+$y]=$nodes2[$x];
}
$nodes=$nodes1;
}
return $nodes;
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.xml-parse.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45725
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45725&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45725&report=yes
Search -- http://master.php.net/manage/user-notes.php