Welcome to the Monastery | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Nice! BTW, the idea behind this module is not just laziness. Yes, as a Lazy Perl programmer I saw no need to have one line of extra code per element that could be avoided. There's another issue: This code is much more fit for my server. XML::Writer generates code on the fly, that's nice and efficent, but inadequate for my needs. In my server, which uses XML I have basically this:
Here's how it works: The client sends one or more commands inside <data>. I make a <data> element, and start parsing, generating XML during the process. Then I send the whole reply at once. With XML::Writer there's the problem of that <data></data> will be sent if there's no output because it's impossible to determine whether XML has been generated or not. In my case, however, it's trivial to count the number of children. Another issue is rolling back XML generation. My parser works by calling callbacks for every registered command, which then may generate XML. A command might generate a tree and send it to the client. But, what happens when it's in the process of generating the tree and something suddenly goes wrong? XML::Writer will have already sent the partial output to the socket. The client will get incomplete data, or very possibly, invalid XML. Since the server will continue processing and try to reply to the next command, the client might not be able to parse it. Of course I could make it close all the elements, and then append an error message, but that's still not good. Parsing goes from top to bottom, so first it'd interpret the partial results, and only then get to the error message. My module lets me remove a subtree at any time I want. So I can start generating, remove the results I got so far, and put an error message in its place. In reply to Re: Re: XML::Maker
by vadim_t
|
|