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">[email protected]</segment> <segment bytes="608371" number="2">[email protected]</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 Link to comment https://forums.phpfreaks.com/topic/100795-solved-xml-reading/ 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 Link to comment https://forums.phpfreaks.com/topic/100795-solved-xml-reading/#findComment-515502 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">[email protected]</segment> <segment bytes="608371" number="2">[email protected]</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 />"); } ?> Link to comment https://forums.phpfreaks.com/topic/100795-solved-xml-reading/#findComment-515514 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 Link to comment https://forums.phpfreaks.com/topic/100795-solved-xml-reading/#findComment-515947 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 Link to comment https://forums.phpfreaks.com/topic/100795-solved-xml-reading/#findComment-515966 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.