Beefy Boxes and Bandwidth Generously Provided by pair Networks
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:

my $root = new XML::Maker("data"); $parser->parse("message"); send_to_client($root->make());

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
in thread XML::Maker by vadim_t

Title:
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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-24 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found