Jump to content

back to basics, what am i missing?


dflow

Recommended Posts

nothing is echoed

for the second foreach??? :confused: :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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.