A few years ago, I tried to parse HTML (not XHTML, which is XML) from an older site with XML::XPath and it blew up rather impressively. The Web pages I was trying to parse were absolutely not valid XML and I decided to just use HTML::Parser and analyze the parse event stream rather than try to massage the HTML into something resembling XML. Which was annoying, because XPath queries would have made my code much cleaner.

HTML::Parser seems to be far more tolerant of ... stuff ... in its input. I suggested it here because the input is HTML (not XHTML) and the problem does not care about the larger document structure, so a sliding window on the low-level parse events is sufficient. Potentially, this could even deliver better latency, if the problem is or can be a "live" transformation.

Thanks for the link; that is an interesting node. The first thing I thought was "XHTML? So it is guaranteed to be valid XML?" and my first attempt at a solution would probably use XML::XPath.


In reply to Re^7: Match text from txt to html by jcb
in thread Match text from txt to html by corfuitl

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.