I'm not aware of any problems with parsing non-standard HTML. HTML is so mutable and browser dependant that unless you are using a tool that is requires a specific DTD, the code you use should be "fault tolerant", so to speak. As a side note, I'd recommend HTML::TokeParser::Simple (full disclosure: I wrote it). It makes your code shorter and easier to read. Here's a small demo.

#!/usr/bin/perl -w use strict; use HTML::TokeParser::Simple; use Data::Dumper; my $pseudo_html; { local $/; $pseudo_html = <DATA>; } print Dumper parse_column_list( $pseudo_html ); sub parse_column_list { my ($str) = @_; my $p = HTML::TokeParser::Simple->new(\$str); my (@cl, $label, %attr); my %attr_default = ( na => 0 ); while(my $t = $p->get_token) { if ( $t->is_start_tag( 'column' ) ) { $label = ''; %attr = (%attr_default, %{$t->return_attr}); } elsif ( $t->is_end_tag( 'column' ) ) { push @cl, { %attr, label => $label }; } else { $label .= $t->return_text; } } return \@cl; } __DATA__ <column>Colum <b>One</b> Header</column> <column>Column <u>Two</u> Header</column> <column na="1">Etcetera</column>

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to Re: Parsing pseudo-HTML with HTML::TokeParser by Ovid
in thread Parsing pseudo-HTML with HTML::TokeParser by mp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.