Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #16407
| Message-ID | <2030773.c2UJNlqvMH@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-10-05 01:25 +0200 |
| Subject | Re: appendChildren versus innerhtml |
| Newsgroups | comp.lang.javascript |
| References | <DfmdneLFAvpwlfPNnZ2dnUVZ_uWdnZ2d@westnet.com.au> <2931754.sreIk3pbUD@PointedEars.de> |
| Followup-To | comp.lang.javascript |
Followups directed to: comp.lang.javascript
Thomas 'PointedEars' Lahn wrote: > Andrew Poulos wrote: >> If the server can return "arbitrary" but valid HTML such as >> […] >> how can you possibly parse it and use createElement/appendChild to >> recreate the HTML. Currently I'm using innerHTML. > > You can parse this efficiently using a regular expression containing token > patterns matching grammar atoms in alternation and > RegExp.prototype.exec(), then apply createElement/appendChild on the > result. CAVEAT: The RegExp must have the `global' flag set so that exec() looks for all matches and control can exit the loop in which it is used when exec() returns `null'. Otherwise the loop will be endless if there is a first match, and your script engine and browser (tab) will hang. Also, if there are two atoms with the same prefix, the first-match-wins rule inherent to RegExp's alternation (as opposed to the longest-match-wins rule usually found in parsers) becomes a problem. I have found two ways to work around that: If the relevant subpatterns match strings of fixed length, you can put the subpattern matching the longest string first. Otherwise you will have to loop through the patterns and match each from the same current offset in the string; the longest match wins, and if there are two or more matches of same length, the first match should win (so you should arrange your subpatterns accordingly or implement precedence otherwise). But this is probably not a concern for parsing HTML. PointedEars -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
appendChildren versus innerhtml Andrew Poulos <ap_prog@hotmail.com> - 2012-10-05 08:08 +1000
Re: appendChildren versus innerhtml Danny <dann90038@gmail.com> - 2012-10-04 15:41 -0700
Re: appendChildren versus innerhtml Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-05 01:02 +0200
Re: appendChildren versus innerhtml Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-05 01:25 +0200
Re: appendChildren versus innerhtml Andrew Poulos <ap_prog@hotmail.com> - 2012-10-05 09:58 +1000
Re: appendChildren versus innerhtml Martin Honnen <mahotrash@yahoo.de> - 2012-10-05 11:36 +0200
Re: appendChildren versus innerhtml Andrew Poulos <ap_prog@hotmail.com> - 2012-10-06 18:31 +1000
Re: appendChildren versus innerhtml Matt McDonald <matt@fortybelow.ca> - 2012-10-05 15:46 -0400
csiph-web