By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,480 Members | 1,231 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,480 IT Pros & Developers. It's quick & easy.

Search simplexml_load_file() object

100+
P: 384
How can I search the object from simplexml_load_file() to pull out certain nodes? Haven't had any luck searching for help on it?
May 6 '10 #1
Share this Question
Share on Google+
5 Replies


Dormilich
Expert Mod 5K+
P: 8,639
try the manual. Id recommend the xpath() methods
May 6 '10 #2

100+
P: 384
I'm trying the below code, not sure if I'm understanding xpath correctly or not? I need to sort the output in DESC order.
Expand|Select|Wrap|Line Numbers
  1. $xml = simplexml_load_file($file) or die ("Unable to load XML file!");
  2.  
  3. foreach ($xml->releases->release as $release) {
  4.     $data .= $release->xpath("date");
  5.  
  6.     print_r($data);
  7. }
May 11 '10 #3

Dormilich
Expert Mod 5K+
P: 8,639
erm, SimpleXMLElement::xpath() returns an array … so any use of a string operator (.) will make a string out of the array.
May 11 '10 #4

100+
P: 384
Ok, I understand it will return an array so in the example I have above it will return an array with all the date nodes as that's what I've specified. How would I specify it to return all the nodes for each entry instead of the single node 'date' for each entry in the XML file?

Will this just return the whole file as an array?
Expand|Select|Wrap|Line Numbers
  1. $data = $xml->xpath('root')
May 11 '10 #5

Dormilich
Expert Mod 5K+
P: 8,639
How would I specify it to return all the nodes for each entry instead of the single node 'date' for each entry in the XML file?
hard to tell without the XML, but you will get an Array, that has all the nodes according to the XPath expression.
May 11 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.