Download the PHP package g-scalvini/xml_htmlsax3 without Composer
On this page you can find all versions of the php package g-scalvini/xml_htmlsax3. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download g-scalvini/xml_htmlsax3
More information about g-scalvini/xml_htmlsax3
Files in g-scalvini/xml_htmlsax3
Package xml_htmlsax3
Short Description A SAX parser for HTML and other badly formed XML documents. Fork from pear/XML_HTMLSax3. More info available on: https://pear.php.net/package/XML_HTMLSax3
License PHP-3.01 LGPL-3.0-only
Informations about the package xml_htmlsax3
$Id: Readme,v 1.4 2004/06/02 14:33:38 hfuecks Exp $ ++Introduction XML_HTMLSax3 is a SAX based XML parser for badly formed XML documents, such as HTML.
The original code base was developed by Alexander Zhukov and published at http://sourceforge.net/projects/phpshelve/. Alexander kindly gave permission to modify the code and license for inclusion in PEAR.
PEAR::XML_HTMLSax3 provides an API very similar to the native PHP SAX extension (http://www.php.net/xml), allowing handlers using one to be easily adapted to the other. The key difference is HTMLSax will not break on badly formed XML, allowing it to be used for parsing HTML documents. Otherwise HTMLSax supports all the handlers available from Expat except namespace and external entity handlers. Provides methods for handling XML escapes as well as JSP/ASP opening and close tags.
Version 1.x introduced an API similar to the native SAX extension but used a slow character by character approach to parsing.
Version 2.x has had it's internals completely overhauled to use a Lexer, delivering performance approaching that of the native XML extension, as well as a radically improved, modular design that makes adding further functionality easy.
Version 3.x is about fine tuning the API, behaviour and providing a mechanism to distinguish HTML "quirks" from badly formed HTML
A big thanks to Jeff Moore (lead developer of WACT: http://wact.sourceforge.net) who's largely responsible for new design, as well input from members at Sitepoint's Advanced PHP forums: http://www.sitepointforums.com/showthread.php?threadid=121246.
Thanks also to Marcus Baker (lead developer of SimpleTest: http://www.lastcraft.com/simple_test.php) for sorting out the unit tests.
++Uses Some particular situations where XML_HTMLSax3 can be useful include;
- Template Engines (see WACT for example: http://wact.sf.net)
- Parsing XML documents (such as those online) where the source is out of your control and Expat is choking because it's badly formed.
- Converting HTML to XHTML
- Reading HTML based content from a database and converting to PDF (with help from a PDF generation library and probably PEAR::XML_SaxFilters as well)
- Parsing ASP(.NET) and JSP pages.
- Creating a PHP-GTK based web browser? A PHP CSS Parser exists: http://www.phpclasses.org/browse.html/package/1081.html
++Features
-
Won't "break" on badly formed XML. May in some instances get it "wrong" (see Limitations) but will continue parsing.
-
Provides an API similar to the native PHP XML extension so switching code from one to the other is typically minimal effort.
-
Can be instructed to behave in more or less the same manner as SAX, when dealing with linefeeds, tabs and XML entities
- In addition to handling basic XML elements attributes and data also
capable of dealing with;
- Processing instructions e.g. / <?xml ?> etc. Within PI's XML entities are not parsed (i.e. ignore < and > )
- XML Escape markup such as <! >, and <![CDATA[ ]]>. Within this XML entities are not parsed (useful for JavaScript, for example)
- JSP / ASP (JASP) marked up with <% %>. Note: You will need to deal with <%@ %> and <%= %> yourself. With JASP markup XML entities are not parsed
++Usage Notes
-
Performance-wise, it runs faster on PHP 4.3.0 thanks to strspn() and strcspn() supporting position arguments. For older PHP versions while loops are used to achieve the same effect, meaning a slightly higher overhead. Note also that setting XML options with XML_HTMLSax3::set_option() also slows down the parser, the options being handled by "decorators" which perform some further formatting on XML events which have already been parsed.
-
By default, no parser options are set
-
Regarding the XML_OPTION_ENTITIES_PARSED, this uses the html_entity_decode() function which is only available in PHP 4.3.0+. To get round this, HTMLSax checks your PHP version and for the function name html_entity_decode. If not found, it defines a function which mirrors the behavior of the native PHP html_entity_decode(). Both XML_OPTION_ENTITIES_PARSED and XML_OPTION_ENTITIES_UNPARSED can be used down to PHP version 4.0.5, due to the regular expression used to find entities.
-
For attributes which have just a name but no value e.g.
- JASP directives like <%@ and <%= will be not be regarded as special. I.e. you will get back the @ or % from the contents of the JASP block and have to deal with these yourself.
++ Limitations
-
XML_HTMLSax3 only supports use of PHP classes as callback handlers; there is no support for using PHP functions as handlers.
-
The only weird behaviour is for attributes which only have a left quote or apostrophe e.g.
Some Text"; This is a trade off against allowing XML entities like < and > to appear inside attributes. -
Although the package name might suggest otherwise, XML_HTMLSax3 currently has no special knowledge of HTML (i.e. there is no understanding of whether a given HTML document is well formed or not, according to HTML's rules). XML_HTMLSax3 is primarily intended as a SAX based parser that will not complain about structure of a document it is asked to parse. It even does a fair job of parsing http://static.php.net/www.php.net/images/php.gif ... Version 3.x will introduce some basic knowledge of HTML grammar to help with identifying HTML "quirks".
-
elements containing < or > characters; these will be treated as new elements triggering the listeners. Make sure that any JavaScript inside is marked either with an XML comment or a CDATA block <[CDATA[ ]]> Alternatively define open / close handlers which watch for elements as a special case, so that any further events triggered within them are handled as part of the element.
- If you change the handlers once parsing has started, you will need to re-set and parser options you have defined
++ Example Use Further examples are available in the examples directory of this package.