Skip to content
FB55 edited this page Jan 9, 2012 · 10 revisions

##Usage

var Parser = new htmlparser.Parser(<obj> handler[, <obj> options]);

##Streaming To Parser

while (...) {
    ...
    parser.write(chunk);
}
parser.done();

##Events

Names for the keys of the handler object. Only functions are valid values (the parser will break otherwise).

  • onopentag(<str> name, <obj> attributes)
  • onopentagname(<str> name)
  • onattribute(<str> name, <str> value)
  • ontext(<str> text)
  • onclosetag(<str> name)
  • onprocessinginstruction(<str> name, <str> data)
  • oncomment(<str> data)
  • oncommentend()
  • oncdatastart()
  • oncdataend()
  • onerror(<err> error)
  • onreset()

##Methods ###write (alias: parseChunk) Parses a chunk of data and calls the corresponding callbacks.

###end (alias: done) Parses the end of the buffer and clears the stack, calls onend.

###reset Resets buffer & stack, calls onreset.

###parseComplete Resets the parser, parses the data & calls end.

##Option: xmlMode Indicates whether special tags (<script> and <style>) should get special treatment and if "empty" tags (eg. <br>) can have children. If false, the content of special tags will be text only.

For feeds and other XML content (documents that don't consist of HTML), set this to true. Default: false.

##Option: lowerCaseTags If set to true, all tags will be lowercased. This has noticeable impact on speed, so it defaults to false.

Clone this wiki locally