note 45725 deleted from function.xml-parse by aidan
| From: | aidan@php.net | Date: | Thu, 16 Sep 2004 12:03:12 +0000 |
| Subject: | note 45725 deleted from function.xml-parse by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76822@lists.php.net to get a copy of this message | ||
Note Submitter: petrek at bimbo dot fjfi dot cvut dot cz
----
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;
}
}
?>