Page 1 of 1
Can't flush() text/xml type?
Posted: Sat Sep 09, 2006 7:03 pm
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.
Posted: Sat Sep 09, 2006 7:44 pm
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.
Posted: Sat Sep 09, 2006 8:05 pm
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

Posted: Sat Sep 09, 2006 9:02 pm
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.
Posted: Sat Sep 09, 2006 9:12 pm
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 ?
Posted: Sat Sep 09, 2006 9:14 pm
by feyd
Avoid nesting containers.

Posted: Sat Sep 09, 2006 9:35 pm
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
Posted: Sat Sep 09, 2006 9:51 pm
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?
Posted: Sat Sep 09, 2006 10:08 pm
by misterk
feyd | Please use 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
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]
Posted: Sun Sep 10, 2006 6:28 am
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.