Do you know where your variables are? | |
PerlMonks |
Re: Dynamically cleaning up HTML fragmentsby halfcountplus (Hermit) |
on Sep 24, 2010 at 00:13 UTC ( [id://861697]=note: print w/replies, xml ) | Need Help?? |
>>We should reject tags that do not have certain mandatory attibutes. No "a" without an href for example. Local anchors do not have "href" as an attribute, they have a "name", eg <a name="local page anchor">here</a> ;) Are you familiar with the event driven HTML::Parser? I have not used it to clean invalid source, but here's an idea (eg): when your start tag handler hits an img tag, put the entire tag text into an otherwise null global. In both the end and start tag handler, you check this global for content; if the img is not closed add / to it. Alternately, I can tell you for a fact that HTML::Parser treats / used XHTMLishly (ie, not the first character in the tag) as an attribute. Therefore, with tags like image you can check for the / attribute and if not present, do the edit. The rest of your requirements -- stripping certain tags, working with attributes, checking for text inside p tags, etc. -- can also easily be accomplished via HTML::Parser, but you will have to write some code to do it.
In Section
Seekers of Perl Wisdom
|
|