in reply to Re: So Simple, Yet no tutorial covers it
in thread So Simple, Yet no tutorial covers it

My own preference is to turn the HTML into valid XML and then parse the XML. There are a number of ways to do this. One way is to use CPAN modules to change the HTML into POD and the POD into XML. I do not know of a module which will change HTML into XML directly.

Once I have XML I can then parse using XML::DOM. That way I can concentrate on learning how to use XML::DOM well by using it for all markup, both HTML and XML.

I respect the work that went into making HTML::Parser. But the next version of HTML called XHTML is going to be XML compliant. All of the XML parsers will work on it, and I do not see why we would be needing a specialized HTML parser.

  • Comment on Re: Re: So Simple, Yet no tutorial covers it

Replies are listed 'Best First'.
Re: Re: Re: So Simple, Yet no tutorial covers it
by mirod (Canon) on Jan 22, 2001 at 04:45 UTC

    I do not know of a module which will change HTML into XML directly

    Install XML::Pyx and HTML::Parser, then do :

    pyxhtml myfile.html | pyxw > myfile.xhtml

    Et voila!

    Of course if your original HTML is full of font tags and the likes it might be quite difficult to do anything even with the XML version.

    And as merlyn would mention if he was around development on HTML has stopped at the W3C and XHTML is the official successor and it _is_ XML compliant (although nothing is quite that simple and some XML tools, especially editors, might not quite like it).

    And now is time for one of my pet peeves: As for using XML::DOM, quite frankly I don't know anybody who has used the DOM and who likes it. And that includes me and several other people who have written DOM tutorials! If you're looking at XML modules XML::Pyx is great for simple processing, XML::Simple would also work for something like the original format, of course my own XML::Twig works fine, and finally if you want to use DOM-like objects XML::XPath is probably much easier to use, besides being faster, more powerful and better supported. OK, I think that was the last time I bother you with my anti-DOM crusade! Actually I am not alone there, the people who wrote JDOM used to have a "Say NO to DOM" logo.

      Right now I have only used the XML DOM for one project. Navigation of the DOM tree is hard for me to follow. My hope had been that as I got more used to the DOM it would become second nature to me.

      Your post leads me to believe that the problems with using the DOM directly are not going to go away as I become more familiar with it.

      I am wondering whether for me XML::XPath for me might be the way to go. XPath is a W3C standard and a variety of languages implement it. At my company we may shift our development work from Perl to Java someday and I would like to be able to continue to use the same XML tools in Java as those I know and love in Perl.