0

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</url>
 <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?

Josh Davis
  • 28,400
  • 5
  • 52
  • 67
  • A valid XML document requires a root element, so I strongly suggest to wrap the links into a root element ``. Also do not use ``, `` and so on, but `` or just ``. The numbering is implicit. Also check http://stackoverflow.com/questions/1560827/php-simplexml-check-if-a-child-exist and http://stackoverflow.com/questions/2129241/php-using-simplexml-to-loop-through-all-levels-of-an-xml-file – Gordon Feb 24 '10 at 17:31

1 Answers1

1

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

Josh Davis
  • 28,400
  • 5
  • 52
  • 67