473,473 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to call a class function from XML

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

<template>
<div id="displayDivOne" src="mkNav()" />
......etc.
</template>

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] = '<div id="'.$adiv[@id].'">';
$myfunc = $adiv[@src];

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

$this->divs[$cnt] .= '</div>';
$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.

Oct 3 '07 #1
1 3506
On 3 Okt., 21:44, salmobytes <Sandy.Pittendr...@gmail.comwrote:
Let's say I have some XML that looks vaguely like:

<template>
<div id="displayDivOne" src="mkNav()" />
......etc.
</template>

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] = '<div id="'.$adiv[@id].'">';
$myfunc = $adiv[@src];

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

$this->divs[$cnt] .= '</div>';
$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

<xsl:foreach select="template/div">
// this line calls the php function
$this->divs[$cnt] = <xsl:value-of select="php:function(@func)"/>;
</xsl:foreach>

Maybe this is a solution of your problem
Oct 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Supa Hoopsa | last post by:
I am using a treeview and within each node, I want to store the name of the function that was called to create the node's data. Then whenever a user selects this node, I want to be able to call...
6
by: komal | last post by:
hi all basically my problem is i have to write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function...
7
by: Rajan | last post by:
Hi All C++ experts My problem is regarding calling templatise class function please see the code snip shot #include<iostream> using namespace std void fun(char*);
3
by: zx.zhangxiong | last post by:
Dear all, I'm puzzled about the usage of class member function. Any help would be appreciated. class Account { ...
1
by: wierus | last post by:
Hello, i have a problem. I write my first class in python so i'm not a experience user. I want to call a function in another function, i tried to do it in many ways, but i always failed:( I...
6
by: marco_segurini | last post by:
Hi, the following sample code shows a compiler error I get trying to build some old code with the last CL compiler (vers 13.10.3077): //----- begin #include <iostream> namespace ns {
4
by: Bonato Pierantonio | last post by:
Hi All, It is possible inside a SCRIPT tag in the HTML page to call a SUB or FUNCTION write in the codebehind ? Example in the HTML <SCRIPT Language=vbscript> sub mySub call mySecondSub end...
4
by: Javier | last post by:
Hello, is this possible? I have a pure virtual function in the base class (to force the programmers of the derived classes to have this function implemented) but I want to call the derived class...
11
by: dolphin | last post by:
Hi All! I have a question that how to call a function just using a string. For example There is a .cpp file named a.cpp.There are some functions::fun1() fun2() fun3(). I have another fucntion...
5
by: robbiesmith79 | last post by:
Hey fellow nerds, Take this code for example: class hello { function world() { echo "Hello"; } }
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.