The comment matching subexpression is way too liberal. How it really works is that <! opens a markup declaration, and within such, a -- double dash starts a comment and another one terminates the comment. In other words, <!-----> (5 dashes) cannot be part of a well-formed document: <! starts the declaration, -- starts a comment, -- closes it, but then there’s an extraneous - dash which is outside the comment and is a markup declaration syntax error. OTOH, <!------> (6 dashes) is fine, except it will comment out much more than you think, because the first 4 dashes open an close an empty comment, and then the last two dashes open a comment that is not closed at this point. However, if you write something like <!--- --> (3 dashes, space, 2 dashes), that’s fine: the first 2 dashes open the comment, the next dash is lone so it’s part of the comment (along with the space that follows), and the last 2 dashes close the comment.

Likewise, your parsing for the XML PI is too simpleminded; additionally, you have no provision for parsing other kinds of PIs at all.

You may have more errors; I didn’t look any harder than that.

You’d do well to just read the spec; it really isn’t prohibitively big or difficult to understand, and if you want to write a correct parser, there’s no way around it.

Because despite claims to the contrary, what you’re doing is parsing. And regexen are certainly a fine tool to do that. The oft-repeated advice is because people who use regexen usually don’t actually parse, and in general, do not have a task that merits the effort required to write a complete, correct parser on their own either, so telling them to use an existing parser is exactly what they need.

Makeshifts last the longest.


In reply to Re: Tokenizing XML by Aristotle
in thread Tokenizing XML by Skeeve

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.