Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

DTD for XML - What is the best parser?

by gmpassos (Priest)
on May 26, 2004 at 01:16 UTC ( #356424=perlquestion: print w/replies, xml ) Need Help??
gmpassos has asked for the wisdom of the Perl Monks concerning the following question:

Felow Monks,

All of use have listen a lot about XML, and all the tools that exits in CPAN for that. Now I'm looking for a good DTD parser to use. I have never listen anything about DTD for XML in Perl yet, so, I'm asking for your opinions on that.

Looking on CPAN I have found this 2 modules:

  • XML::DTDParser
  • XML::ParseDTD
  • But I haven't tested them yet. I'm looking for something stable, and in the parsed tree, that need to give me all the informations that a DTD can have. Any other extra resource for now is not important.

    Graciliano M. P.
    "Creativity is the expression of the liberty".

    Replies are listed 'Best First'.
    Re: DTD for XML - What is the best parser?
    by castaway (Parson) on May 26, 2004 at 05:13 UTC
      You missed XML::LibXML::Dtd, LibXML requires you to install the c library libxml2, but its the most complete XML creator/parser out there, as far as I can see. That's what I picked when I was looking for a DTD Parser. I can't remember now what the two you mention were like, but I know I found LibXML more useful.

      (And started to create a DTD verifier/generator, since apparently there is/was a complete lack of those too.)


    Re: DTD for XML - What is the best parser?
    by mirod (Canon) on May 26, 2004 at 09:25 UTC

      What do you want to do with the DTD?

      • if you want to check documents against it, then you can use XML::Checker or XML::LibXML (set validation on by using $parser->validation(1);),
      • if you need info about the DTD then good ole XML::Parser allows you to set handlers on the various events in the DTD,
      • then if what you need is to get the default attributes or to expand entities in the XML, I usually do this as a separate process, using a standalone tool. xmllint which comes with libxml2 should do this, I use osx as my data is originally in SGML.
    Re: DTD for XML - What is the best parser?
    by DaveH (Monk) on May 26, 2004 at 15:18 UTC


      I have recently used XML::DTDParser for a project and I found that it was exactly what I was looking for. It provides a convenient Perl datastructure representing a DTD which does exactly what you want: parses a DTD. There is no extra "fluff" or additional functionality which gets in the way of achieving what you want.

      This said, I was not concerned with performance, nor was I writing code which I expected to be extensively reused in other projects (or reviewed by other developers). I was just writing a quick and dirty script to solve a problem, which is I believe exactly what XML::DTDParser's author (Jenda) had in mind when writing this module.

      If you want something simple, I would recommend XML::DTDParser. If you are after a more complete XML library, I would look into XML::LibXML.

      I hope this helps.


      -- Dave :-)


    Log In?

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: perlquestion [id://356424]
    Approved by DaWolf
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (7)
    As of 2018-02-21 17:55 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (285 votes). Check out past polls.