开发者

PHP: passing an xml node to function

i'm trying to pass an xml node to a function but can't figure out how - here's my xml markup:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
<form>
<item>
    <id>frm1</id&g开发者_StackOverflow中文版t;
    <dbID>1</dbID>
    <visible>1</visible>
</item>
</form>
<form>
<item>
    <id>frm2</id>
    <dbID>2</dbID>
    <visible>1</visible>
</item>
</form>
</root>

when setting up a foreach loop - how's the syntax to iterate through the xml and passing the whole node to a function? i've tried something like:

foreach($xml as $ctlXML => $value)
{
    $ctl = generateCTL($ctlXML);
}

but it doesn't work as it should.

thanks


If you are using SimpleXML it is simple as

$xml = simplexml_load_file($path_to_file);
foreach($xml->form as $form){
    $ctl = generateCTL($form->item);
}

Be careful - $form->item is an object

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜