dflow Posted February 5, 2012 Share Posted February 5, 2012 nothing is echoed for the second foreach??? :confused: foreach($pictures as $picture) -im breaking cause it's a large file $doc = new DOMDocument(); $doc->load('accommodation.xml'); $i = 0; $accommodations = $doc->getElementsByTagName('accommodation'); foreach($accommodations as $accommodation) { if(++$i > 2) break; $supplierID = $accommodation->getElementsByTagName('code')->item(0)->nodeValue; $pictures = $accommodation->getElementsByTagName('pictures')->item(0)->nodeValue; $pictures=array(); foreach($pictures as $picture) { echo $url = $picture->getElementsByTagName('url')->item(0)->nodeValue; } }//end //XMl schema <?xml version="1.0" encoding="utf-8"?> <accommodations> <accommodation> <code>1</code> <pictures> <picture> <url>http://example.com/images.k.jpg</url> </picture> </pictures> Quote Link to comment https://forums.phpfreaks.com/topic/256462-back-to-basics-what-am-i-missing/ Share on other sites More sharing options...
Danny696 Posted February 5, 2012 Share Posted February 5, 2012 Would it not just be echo $picture->getElementsByTagName('url')->item(0)->nodeValue; Quote Link to comment https://forums.phpfreaks.com/topic/256462-back-to-basics-what-am-i-missing/#findComment-1314753 Share on other sites More sharing options...
digibucc Posted February 5, 2012 Share Posted February 5, 2012 correct, they're trying to set a variable and echo it at the same time. if you need that set to the $url variable, do this: <php $url = $picture->getElementsByTagName('url')->item(0)->nodeValue; echo $url ?> otherwise do what danny said. Quote Link to comment https://forums.phpfreaks.com/topic/256462-back-to-basics-what-am-i-missing/#findComment-1314761 Share on other sites More sharing options...
dflow Posted February 5, 2012 Author Share Posted February 5, 2012 correct, they're trying to set a variable and echo it at the same time. if you need that set to the $url variable, do this: <php $url = $picture->getElementsByTagName('url')->item(0)->nodeValue; echo $url ?> otherwise do what danny said. still nada Quote Link to comment https://forums.phpfreaks.com/topic/256462-back-to-basics-what-am-i-missing/#findComment-1314763 Share on other sites More sharing options...
digibucc Posted February 5, 2012 Share Posted February 5, 2012 var dump your object to make sure it's set and the structure is what you are using <?php var_dump($picture->getElementsByTagName('url')->item(0)->nodeValue);?> and see if it has anything. if not, <?php var_dump($picture); ?> if it's empty, you have a deeper problem, if it's not empty, you're not following the children properly, so just go one by one until you find the mistake. Quote Link to comment https://forums.phpfreaks.com/topic/256462-back-to-basics-what-am-i-missing/#findComment-1314764 Share on other sites More sharing options...
dflow Posted February 5, 2012 Author Share Posted February 5, 2012 var dump your object to make sure it's set and the structure is what you are using <?php var_dump($picture->getElementsByTagName('url')->item(0)->nodeValue);?> and see if it has anything. if not, <?php var_dump($picture); ?> if it's empty, you have a deeper problem, if it's not empty, you're not following the children properly, so just go one by one until you find the mistake. they are empty i var_dumped($picture) $picture=array(); does not set it as an array when doing this: var_dump($pictures = $accommodation->getElementsByTagName('pictures')->item(0)->nodeValue); i get results?? Quote Link to comment https://forums.phpfreaks.com/topic/256462-back-to-basics-what-am-i-missing/#findComment-1314780 Share on other sites More sharing options...
digibucc Posted February 5, 2012 Share Posted February 5, 2012 for $picture to be empty and $picture[/size][/color]->[/size][/color]getElementsByTagName[/size][/color]([/size][/color]'url'[/size][/color])->[/size][/color]item[/size][/color]([/size][/color]0[/size][/color])->[/size][/color]nodeValue to have results, something is wrong, did you try the var_dump in the same exact place? $picture should be an object, not an array - why are you trying to make it an array? you said you get results, but what. what var dump says specifically is very useful in debugging why your echo isn't working. maybe it's an object or something? so copy paste the exact result of the var dump of [/size][/color]$picture[/size][/color]->[/size][/color]getElementsByTagName[/size][/color]([/size][/color]'url'[/size][/color])->[/size][/color]item[/size][/color]([/size][/color]0[/size][/color])->[/size][/color]nodeValue Quote Link to comment https://forums.phpfreaks.com/topic/256462-back-to-basics-what-am-i-missing/#findComment-1314816 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.