Can't flush() text/xml type?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
misterk
Forum Newbie
Posts: 5
Joined: Sat Sep 09, 2006 6:57 pm

Can't flush() text/xml type?

Post by misterk »

I have a script that is querying a mysql DB and throwing back the results via <table>,<tr>,<td>'s . The result set may be very large so after each </tr> or </table> I issue a flush() or ob_flush() and everything works perfectly to keep impatient users seeing additional data rather then a blank screen.

However once i converted to returning the results in xml 1.0 it seems to break the ability to flush() and the page will not display until the entire results are returned. Specifically the:

header("Content-Type: text/xml;charset=ISO-8859-1");

seems to break all flush()'s. Is there any way to output buffer the xml formatted results without having to go an ajax route?

Thank in advance for anyone who may be able to help or offer advice.
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

Why are you displaying such a huge result set anyway ( how many records??? ). It would be less intensive if you provide some sort of paging solutions allowing user to scroll through the data.
misterk
Forum Newbie
Posts: 5
Joined: Sat Sep 09, 2006 6:57 pm

Post by misterk »

The result set is dynamic (pre-filtered) based on the user input prior to the results being provided. Paging would be counter productive as the full result set is actually what they are looking to see. The issue I have is if I can actually flush() when the content type is xml ? Ive searched high & low and cant find anything related :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why are you using <table> et al in an XML file? While technically they are perfectly valid XML, wouldn't it be better to use descriptive element names?

I would hazard to guess that the browser is waiting for the container to finish before it tries to display information about it. I think it may be better to use a different tag structure.
misterk
Forum Newbie
Posts: 5
Joined: Sat Sep 09, 2006 6:57 pm

Post by misterk »

The script originally was set up via std. html tables/tr/td layout. Once I converted it to deliver xml I used descriptive element names and employ xslt transformation to control the presentation. So the resultset is strictly xml, however the xsl applies the display logic. Back to the issue at hand lol is there a way to spit out each node rather then the whole container ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Avoid nesting containers. :)
misterk
Forum Newbie
Posts: 5
Joined: Sat Sep 09, 2006 6:57 pm

Post by misterk »

feyd wrote:Avoid nesting containers. :)
Uhmnnnn how do I avoid nested containers in xml? lol Dont I NEED a root element container? lol
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

There's a difference between an element and a container. A container usually is just a placeholder that contains more elements, i.e. <table>

Why don't you stop using output buffering?
misterk
Forum Newbie
Posts: 5
Joined: Sat Sep 09, 2006 6:57 pm

Post by misterk »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I use output buffering because part of the result set contains hyperlinks which may be clicked on. It is necessary that the results are written out as they are generated because some of the results may be quite large and it serves to allow the user to begin clicking away as others are populated ; instead of waiting 2-3 minutes for it to complete.

More Specifically:

Example XML:

[syntax="xml"]<ROOT>
<ELEMENT>
<ID>100</ID>
<URL>http://www.yahoo.com</URL>
<VALUE>$50.00</value>
</ELEMENT>
<ELEMENT>
<ID>100</ID>
<URL>http://www.google.com</URL>
<VALUE>$75.00</value>
</ELEMENT>
<ELEMENT>
<ID>100</ID>
<URL>http://www.msn.com</URL>
<VALUE>$25.00</value>
</ELEMENT>
</ROOT>

This is generated within a for loop -> psuedo code:[/syntax]

Code: Select all

echo "<ROOT>/r/n";
for ($i=0; $i <=$max; $i++){
echo "<ELEMENT>/r/n<ID>".$id."</ID>/r/n<URL>".$url."</URL>/r/n<VALUE>".$value."</VALUE>/r/n</ELEMENT>/r/r";
@ob_flush;
flush();
}
echo "</ROOT>/r/n";

this is just a faaux sample of whats being done... but illustrates the goal..... when done in XHTML <TABLE><TR><TD> it works as desired spitting out one row after another withe each flush(). However once I change to text/xml and spit out xml fields.... no dice.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

XML is parsed when all the tags are closed .. <root> isn't going to be closed until the entire document is downloaded .. therefore flush() will work (it'll send it to the browser) but the browser won't display anything until it's got everything.
Post Reply