YenForYang has asked for the wisdom of the Perl Monks concerning the following question:

Frontier::RPC2, Line 323

It says # FIXME this state machine wouldn't be necessary if we had a DTD.

I don't understand (not too familiar with XML::Parser, but I get the general idea of needing the handler subroutines). How would a XML DTD (because there does exist DTDs and XSDs for XML-RPC) be of any use in removing the if-elsif-else chain?

I'm trying to simplify the code for decoding XML-RPC calls/responses -- i.e. the subroutine decode. As far as I know, Frontier::RPC2 is the fastest Perl xmlrpc decoder available on CPAN, but looking at the code it looks like it code be significantly improved (?))

Side question: doe having an empty sub sub {} for the Proc handler subroutine do anything? Or can it be left out?

EDIT: To be clear, I know what a DTD is. Sorry I didn't clarify. I want to know why it would actually be useful. Because from my current understanding, wouldn't a state machine be needed regardless of the DTD? Or is there some sort of 'plug-in' for the DTD in XML::Parser I'm unaware of?

Replies are listed 'Best First'.
Re: What does this comment mean (Are DTDs of any use to XML::Parser?)
by ikegami (Patriarch) on May 02, 2018 at 22:40 UTC

    That code appears to do schema validation. A DTD defines a schema, and can be used in conjunction with existing validators to perform schma validation.

      I guess I wasn't clear -- what I wanted to say was how would a DTD actually be used in the code. That is, if I were to validate some XML, wouldn't that require some sort of if-elsif anyway? I don't see why having a DTD in particular would help. I was hoping that the comment meant something analogous to "We wouldn't need a bike if we had a car", not something like "We wouldn't need a bike if we had instructions"

        As I said, they would use an *existing* validator.

        my $dtd = XML::LibXML::Dtd->new(...); $doc->validate($dtd);

        Less code means less to maintain. It also means you can use a faster, tested solution (such as the C++ library libxml2 used by XML::LibXML).

A reply falls below the community's threshold of quality. You may see it by logging in.