2

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>
    <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

1
  • 2
    You should show us a bit more code, like how you load the XML (simplexml ? DOM ?), how you call the function, what you get, and what you'd want to get. Commented Mar 21, 2011 at 6:41

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

It should be foreach($xml->form as $form)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.