graham23s Posted April 12, 2008 Share Posted April 12, 2008 Hi Guys, i am trying to parse the information from an .xml or .nzb file which is practically the same as far as i can read a test file is here: <?php <file poster="graham23s" date="1195251842" subject="TEST SUBJECT"> <groups> <group>alt.binaries.test</group> </groups> <segments> <segment bytes="651504" number="1">bN2dncgGHIofhaPanZ2dnUVZ8tvinZ2d@giganews.com</segment> <segment bytes="608371" number="2">bN2dncsGHIoahaPanZ2dnUVZ8tvinZ2d@giganews.com</segment> </segments> </file> ?> to get the information i basically use: <?php // xml testing // $xml_file = "5300538.xml"; // load the nzb // $xml = simplexml_load_file("$xml_file"); // test // foreach ($xml as $details) { print("<b>Date</b> - ") . $details['date']; print("<br />"); print("<b>Posted By</b> - ") . $details['poster']; print("<br />"); print("<b>Subject</b> - ") . $details['subject']; print("<br />"); print("<b>Group</b> - ") . $details['groups']; print("<br />"); print("<br />"); print("<hr />"); } ?> this works great up untill i try to get the child nodes, the group for example, its in groups->group, i foreach all the lines to get them all, i was wondering how best to get the child nodes any input would be great cheers Graham Quote Link to comment Share on other sites More sharing options...
cytech Posted April 12, 2008 Share Posted April 12, 2008 Hello, Can you show me the "dump" of $xml. From $xml = simplexml_load_file("$xml_file"); My initial thought is to do if(is_array($data['element'])){ //we have children } but not sure if simplexml setups children nodes as multilevel arrays. Hence the dump haha Quote Link to comment Share on other sites More sharing options...
Barand Posted April 12, 2008 Share Posted April 12, 2008 <?php $str = '<file poster="graham23s" date="1195251842" subject="TEST SUBJECT"> <groups> <group>alt.binaries.test</group> </groups> <segments> <segment bytes="651504" number="1">bN2dncgGHIofhaPanZ2dnUVZ8tvinZ2d@giganews.com</segment> <segment bytes="608371" number="2">bN2dncsGHIoahaPanZ2dnUVZ8tvinZ2d@giganews.com</segment> </segments> </file>'; $xml = simplexml_load_string($str); print("<b>Date</b> - " . $xml['date']); print("<br />"); print("<b>Posted By</b> - " . $xml['poster']); print("<br />"); print("<b>Subject</b> - " . $xml['subject']); print("<br />"); foreach ($xml->groups as $gp) { print("<b>Group</b> - " . $gp->group); print("<br />"); print("<br />"); print("<hr />"); } ?> Quote Link to comment Share on other sites More sharing options...
graham23s Posted April 13, 2008 Author Share Posted April 13, 2008 thanks guys i have sorted it:) cheers Quote Link to comment Share on other sites More sharing options...
Barand Posted April 13, 2008 Share Posted April 13, 2008 I'll mark it solved then as you haven't Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.