How to call a class function from XML

How to call a class function from XML

am 03.10.2007 21:44:58 von Sandy.Pittendrigh

Let's say I have some XML that looks vaguely like:



I want to use the div line to call a class function, I.E. $this-
>mkNav();
without creating a hard-coded switch statement.

.....I'd like to say something like:
$cnt=0;
foreach ($xml->xpath("/template/div") as $adiv)
{
$this->divs[$cnt] = '

';
$myfunc = $adiv[@src];

$this->divs[$cnt] .= $myfunc;
.....or maybe something like:
eval ("$this->divs[$cnt] .= $myfunc");

$this->divs[$cnt] .= '
';
$cnt++;
}

....but of course none of the above works.
I don't want to have to remember to modify a switch
statement every time I add a new function to the class,
that might end up specified in the XML.

Re: How to call a class function from XML

am 03.10.2007 22:07:02 von Patrick Brunmayr

On 3 Okt., 21:44, salmobytes wrote:
> Let's say I have some XML that looks vaguely like:
>
>
>
> I want to use the div line to call a class function, I.E. $this->mkNav();
>
> without creating a hard-coded switch statement.
>
> ....I'd like to say something like:
> $cnt=0;
> foreach ($xml->xpath("/template/div") as $adiv)
> {
> $this->divs[$cnt] = '

';
> $myfunc = $adiv[@src];
>
> $this->divs[$cnt] .= $myfunc;
> .....or maybe something like:
> eval ("$this->divs[$cnt] .= $myfunc");
>
> $this->divs[$cnt] .= '
';
> $cnt++;
> }
>
> ...but of course none of the above works.
> I don't want to have to remember to modify a switch
> statement every time I add a new function to the class,
> that might end up specified in the XML.

Hi

You could parse the xml file with php xslt processor. The Xslt
Processor class has
a function called registerPHPFunction(). You can find it in the doc!
The you you
could do something like this


// this line calls the php function
$this->divs[$cnt] = ;


Maybe this is a solution of your problem