in reply to Incremental parsing of multiple XML streams?

If it's basic vanilla XML without too much weird stuff, you can use HTML::Parser in "XML mode", setting up your proper callbacks as you recognize the right pieces. HTML::Parser objects take parse method calls which can take arbitrarily read chunks as they come in.

Might not be perfect, but it just might be what you need.

I demonstrate this technique in one of my columns.

Oh, and apparently the XML::LibXML parser has a parse_chunk method which works similar to HTML::Parser's parse method. Try that too.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on •Re: Incremental parsing of multiple XML streams?

Replies are listed 'Best First'.
Re^2: Incremental parsing of multiple XML streams?
by nothingmuch (Priest) on Jan 08, 2005 at 14:17 UTC
    That's a wonderful column, merlyn. IIRC it was the first one by you that I've read (possibly the first about perl I've read ever).

    Although it seems to provide me with a good solution, I think I will go with redhotpenguin's, as it will probably be more robust than HTML::Parser, and I already know for certain that it does exactly what I need.

    Update: Appearantly my memory is pulling tricks on me, that was not so long ago. Nevertheless, it and this one I remember as mind opening, in terms of using one tool to get another's job done.

    -nuffin
    zz zZ Z Z #!perl