While trying to implement this with XML::SAX::Builder, I ran into a problem.

Parsing a SAX stream looks like this:

<p> <i> Italics <b> plus bold </b> </i> </p> start_document start_element : p start_element : i characters : Italics start_element : b characters : plus bold end_element : b end_element : i end_element : p end_document

The HSS stream looks like this:

start_document start_element : b content : plus Bold end_element : b start_element : i content : Italics content : <b>plus Bold</b> end_element : i start_element : p content : <i>Italics <b>plus Bold</b></i> end_element : p end_document

The reason for that, is my tag callbacks, which give you the ability to change a tag and its contents, delete the tag, and or its contents etc. The callback needs access to the contents/child nodes.

So the tree is built from the leaves down, rather than in the traditional manner.

I've implemented a solution, which I have posted here: RFC: HTML::StripScripts::LibXML

Clint


In reply to Re^2: Returning an XML::LibXML::DocumentFragment from HTML::StripScripts by clinton
in thread Returning an XML::LibXML::DocumentFragment from HTML::StripScripts by clinton

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.