Js parsing

Материал из support.qbpro.ru

JavaScript HTML Parser

Handles tag, text, and comments with callbacks. For example, let's say you wanted to implement a simple HTML to XML serialization scheme - you could do so using the following:

 var results = "";
   HTMLParser("<p id=test>hello <i>world", {
     start: function( tag, attrs, unary ) {
       results += "<" + tag;
 
       for ( var i = 0; i < attrs.length; i++ )
 	results += " " + attrs[i].name + '="' + attrs[i].escaped + '"';
 
     results += (unary ? "/" : "") + ">";
   },
   end: function( tag ) {
     results += "</" + tag + ">";
   },
   chars: function( text ) {
     results += text;
   },
   comment: function( text ) {
     results += "<!--" + text + "-->";
   }
 });
 
 results == '<p id="test">hello <i>world</i></p>"


статья

HTML-парсер на чистом JavaScript