shauntain Posted November 5, 2009 Share Posted November 5, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/180375-solved-help-parsing-xml-while-loop-is-destroying-data-wtf/ Share on other sites More sharing options...
sKunKbad Posted November 5, 2009 Share Posted November 5, 2009 Why not simpleXML? Quote Link to comment https://forums.phpfreaks.com/topic/180375-solved-help-parsing-xml-while-loop-is-destroying-data-wtf/#findComment-951574 Share on other sites More sharing options...
shauntain Posted November 5, 2009 Author Share Posted November 5, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/180375-solved-help-parsing-xml-while-loop-is-destroying-data-wtf/#findComment-951576 Share on other sites More sharing options...
sKunKbad Posted November 5, 2009 Share Posted November 5, 2009 I only asked because the docs don't show any good examples, and the code you have shown doesn't make any sense to me. SimpleXML is what I've been using, and they don't call it simple for nothing. Quote Link to comment https://forums.phpfreaks.com/topic/180375-solved-help-parsing-xml-while-loop-is-destroying-data-wtf/#findComment-951596 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2009 Share Posted November 5, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/180375-solved-help-parsing-xml-while-loop-is-destroying-data-wtf/#findComment-951741 Share on other sites More sharing options...
shauntain Posted November 5, 2009 Author Share Posted November 5, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/180375-solved-help-parsing-xml-while-loop-is-destroying-data-wtf/#findComment-951962 Share on other sites More sharing options...
shauntain Posted November 5, 2009 Author Share Posted November 5, 2009 Nm.. i got it... for some reason my xml was double reading the AverageFeedbackRating and the second time it was null. Added isset and it works. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/180375-solved-help-parsing-xml-while-loop-is-destroying-data-wtf/#findComment-951967 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.