Re: Re: Package Proposal: HTML_Sax

From: Date: Sun, 11 May 2003 14:51:37 +0000
Subject: Re: Re: Package Proposal: HTML_Sax
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-16142@lists.php.net to get a copy of this message
Harry Fuecks wrote:
Hi Alan, OK - have put the sources are up here; http://code.phppatterns.com/HTML_Sax/HTML_Sax.phps http://code.phppatterns.com/HTML_Sax/State_Machine.phps http://code.phppatterns.com/HTML_Sax/Attributes_Parser.phps
nice and clean - I personally didnt like the State_Machine :) - as I would have used it as a way to document all the flags rather than writing wrappers for a=1,unset.. isset() etc. eg. just do $this->sm->left_b = 1; if ($this->sm->left_b); ... etc. It will probably speed things up quite a bit as well..
And there's a couple of examples here; http://code.phppatterns.com/HTML_Sax/examples/HTMLtoXHTML.phps http://code.phppatterns.com/HTML_Sax/examples/SimpleExample.phps API docs are up here; http://code.phppatterns.com/HTML_Sax/docs/ Don't have much experience of the tokenizer extension - I guess that would be something equivalent to the DOM API for HTML?
I was refering to this - http://cvs.php.net/co.php/pear/HTML_Template_Flexy/Flexy/Tokenizer.lex?r=1.23, which is a Lex (as in flex equivialant) its designed to be even lower level than sax/domxml eg.
So far I haven't been able to break HTML_Sax as such but there are some situations right now where it won't behave exactly as expected e.g.;
It's pretty easy to fix this with flex - you just check the tag if ($tag == 'script') { $this->yystate(IN_SCRIPT); } <IN_SCRIPT> '</[sS][cC][rR][iI][pP]>' { .... store token or whatever.. $this->yystate(IN_SCRIPT); } <IN_SCRIPT> .* .. ignore... / or store as script.. .. it also handles really weird stuff like <sometag a=> <input type crash> , which is better than IE does :) Anyway - otherwise this code looks great (eg. +1 here) - just repost again with a reminder notice and see if you can get the votes through.. Regards Alan
<script language="javascript"> document.write('<b>Hello World!</b>'); </script> Would trigger events for the <b> and </b> elements. The workaround is; <script language="javascript"> <!-- document.write('<b>Hello World!</b>'); --> </script> Overall, it doesn't really care about whether the "overall picture" of a document makes sense to it - it simply triggers events every time it encounters something looking like a tag - it other words its up to the handler methods to decide what to do with events - probably this example http://code.phppatterns.com/HTML_Sax/examples/HTMLtoXHTML.phps demonstates that - the handler works for the example.html page but might not produce decent XHTML for other pages. Regards, Harry On Sat, 10 May 2003 12:00:12 +0800, Alan Knowles <alan@akbkhome.com> wrote:
Can you make phps available please, I presume it's a hand based tokenizer/parser, I did a few of these before but was never very happy with them (they tended to break easily..), which is why I went down the road of using a lexer in flexy.. - which might worth breaking out as HTML_Lex one day.. Regards Alan
-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.com

« previous php.pear.dev (#16142) next »