Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Dear monks,

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:

<results type='xml'> <result1> ... </result1> <result2> ... </result2> ... <result6000> ... </result6000> </results
or this:
<results type='compact'> RESULT1 ... RESULT2 ... ... RESULT 6000 ... </results>
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!

In reply to Streaming XML output by sgifford

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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> <u> <ul>
  • 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 intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2023-09-26 09:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found