I am working on a Web application implementing a RETS server. The output of most types of transactions is a fairly large XML document. Depending on what the user asks for, it can have a large number of structured elements, or one element with tab-separated data in it. Very roughly, it looks either like this:
<result1> ... </result1>
<result2> ... </result2>
<result6000> ... </result6000>
RESULT 6000 ...
I looked at several XML modules to generate the XML, and settled on XML::LibXML
. The problem I'm running into is that this module, along with the others I looked at, won't output anything until the entire XML document is done. With 6000 fairly large entries, that can be about 18MB of data. When processing it all at once, the user sends the requests then waits up to a minute before seeing anything. In the meantime, the server is chewing up memory to store the document.
The analagous problems with reading XML is solved by SAX, which lets you process the document as it comes in, without holding the whole thing in memory.
Is there a similar way to output XML documents, outputting the data immediately instead of waiting for the whole document to finish but letting a module handle most of the XML details? I would like something a bit more structured than generating the XML by hand and printing it. Ideally it would help format elements and attributes, close tags (or at least warn me if I forget) and otherwise make sure the document was correctly formatted.
Thanks for any suggestions!
Are you posting in the right place? Check out Where do I post X? to know for sure.
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
Want more info? How to link
or How to display code and escape characters
are good places to start.