Jump to content

[SOLVED] Help parsing xml... while loop is destroying data? (WTF)


Recommended Posts

ok guys heres my code...

 

 

                                        $s =  new seller();

 

$reader->read();

$off = new XMLReader();

$off->XML('<Offer>'.$reader->readInnerXML().'</Offer>');

while($off->read()){

if($off->name == "AverageFeedbackRating"){

$s->feedback = $off->readInnerXml();

}

echo $s->feedback;          // will print here

}

                                        echo $s->feedback;                  //no print here

 

Now why can I get output inside the while loop and not outside?  I have tried using setters and getters in my class but no go.  Do I need to pass by value or something?

 

PHP5

 

 

THANK YOU SO MUCH

Why not simpleXML?

 

I suppose I could rewrite my code with simpleXML.  I have a good deal more code that is working correctly so I guess the only reason not to use simpleXML would be because I have other code written.  It just seems strange its not working.

Now why can I get output inside the while loop and not outside?

 

The only time we have seen that symptom is when the actual full code was different than what was posted. Is the code you posted exactly, line for line, nothing added, nothing removed, nothing changed from the actual code?

 

If that is the full actual code, then it is likely that you have a value being assigned in the last iteration through the loop that is either empty or does not display anything when echoed. You see all the lines upto the last line being echoed, then you don't see a double echo of the last line because it was empty/non-displayable both when it was echoed in the loop and outside of the loop. Perhaps use var_dump() instead of echo (both in and outside the loop) to see exactly what data is present.

Now why can I get output inside the while loop and not outside?

 

The only time we have seen that symptom is when the actual full code was different than what was posted. Is the code you posted exactly, line for line, nothing added, nothing removed, nothing changed from the actual code?

 

If that is the full actual code, then it is likely that you have a value being assigned in the last iteration through the loop that is either empty or does not display anything when echoed. You see all the lines upto the last line being echoed, then you don't see a double echo of the last line because it was empty/non-displayable both when it was echoed in the loop and outside of the loop. Perhaps use var_dump() instead of echo (both in and outside the loop) to see exactly what data is present.

 

Yes this code is EXACTLY how it is in my program.  Added in var_dumps... here is a snippet of the response:

 

 

comes in and loops with no vals... here is where the if statement finds the feedbackRating...

 

object(seller)#2 (4) {

  ["price"]=>

  NULL

  ["feedbackRating"]=>

  string(3) "4.7"

  ["totalFeedback"]=>

  NULL

  ["condition"]=>

  NULL

}

object(seller)#2 (4) {

  ["price"]=>

  NULL

  ["feedbackRating"]=>

  string(3) "4.7"

  ["totalFeedback"]=>

  NULL

  ["condition"]=>

  NULL

}

object(seller)#2 (4) {

  ["price"]=>

  NULL

  ["feedbackRating"]=>

  string(0) ""

  ["totalFeedback"]=>

  NULL

  ["condition"]=>

  NULL

}

.... more exact copy of above with no vals....

Then it comes out of the loop and...

 

object(seller)#2 (4) {

  ["price"]=>

  NULL

  ["feedbackRating"]=>

  string(0) ""

  ["totalFeedback"]=>

  NULL

  ["condition"]=>

  NULL

}

 

As you can see it looks like it gets the value and then keeps it for one more iteration of the while loop and then drops it.

 

BTW changed the code at the top to be:

$s->setFeedback( $off->readInnerXml());

        instead of?

$s->feedback = $off->readInnerXml();

 

just incase anyone was going to say I am setting the wrong variable

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.