views:

40

answers:

1

I'm looking to run some kind of loop on some optional XML data.

Nodes would potentially look like this:

<link1>
 <url>http://www.bleh.com&lt;/url&gt;
 <text>Click here</text>
</link1>
<link2>
 <url>bleh.com</url>
 <text>Click here</text>
</link2>

What would be the best method to determine if these nodes exist and parse them accordingly?

+1  A: 

If you're using SimpleXML, then you can simply use isset() to determine whether a node exists.

Josh Davis
But then how would I loop through subsequent nodes link1, link2, etc?
Richard Harrington
With a for loop? Although I should mention that naming all elements `<link/>` would be a much wiser choice.
Josh Davis