wxhtmlparserclasses derived from this handle the generic parsing of html documents: it scans the document and divide it into blocks of tags (where one block consists of beginning and ending tag and of text between these two tags). it is independent from wxhtmlwindow and can be used as stand-alone parser (julian smart's idea of speech-only html viewer or wget-like utility - see inetget sample for example). it uses system of tag handlers to parse the html document. tag handlers are not statically shared by all instances but are created for each wxhtmlparser instance. the reason is that the handler may contain document-specific temporary data used during parsing (e.g. complicated structures like tables). typically the user calls only the parse method. derived from wxobject include files <wx/html/htmlpars.h> see also cells overview, tag handlers overview, wxhtmltag members
wxhtmlparser::wxhtmlparser
wxhtmlparser::wxhtmlparserwxhtmlparser() constructor.
wxhtmlparser::addtagvoid addtag(const wxhtmltag& tag) this may (and may not) be overwritten in derived class. this method is called each time new tag is about to be added. tag contains information about the tag. (see wxhtmltag for details.) default (wxhtmlparser) behaviour is this: first it finds a handler capable of handling this tag and then it calls handler's handletag method.
wxhtmlparser::addtaghandlervirtual void addtaghandler(wxhtmltaghandler *handler) adds handler to the internal list (& hash table) of handlers. this method should not be called directly by user but rather by derived class' constructor. this adds the handler to this instance of wxhtmlparser, not to all objects of this class! (static front-end to addtaghandler is provided by wxhtmlwinparser). all handlers are deleted on object deletion.
wxhtmlparser::addtextvirtual void addword(const char* txt) must be overwritten in derived class. this method is called by doparsing each time a part of text is parsed. txt is not only one word, it is substring of input. it is not formatted or preprocessed (so white spaces are unmodified).
wxhtmlparser::doparsingvoid doparsing(int begin_pos, int end_pos) void doparsing() parses the m_source from begin_pos to end_pos-1. (in noparams version it parses whole m_source)
wxhtmlparser::doneparservirtual void doneparser() this must be called after doparsing().
wxhtmlparser::getfswxfilesystem* getfs() const returns pointer to the file system. because each tag handler has reference to it is parent parser it can easily request the file by calling
wxfsfile *f = m_parser -> getfs() -> openfile("image.jpg"); wxhtmlparser::getproductvirtual wxobject* getproduct() returns product of parsing. returned value is result of parsing of the document. the type of this result depends on internal representation in derived parser (but it must be derived from wxobject!). see wxhtmlwinparser for details.
wxhtmlparser::getsourcewxstring* getsource() returns pointer to the source being parsed.
wxhtmlparser::initparservirtual void initparser(const wxstring& source) setups the parser for parsing the source string. (should be overridden in derived class)
wxhtmlparser::openurlvirtual wxfsfile* openurl(wxhtmlurltype type, const wxstring& url) opens given url and returns wxfsfile object that can be used to read data from it. this method may return null in one of two cases: either the url doesn't point to any valid resource or the url is blocked by overridden implementation of openurl in derived class. parameters type
url
notes always use this method in tag handlers instead of getfs()->openfile() because it can block the url and is thus more secure. default behaviour is to call wxhtmlwindow::onopeningurl of the associated wxhtmlwindow object (which may decide to block the url or redirect it to another one),if there's any, and always open the url if the parser is not used with wxhtmlwindow. returned wxfsfile object is not guaranteed to point to url, it might have been redirected!
wxhtmlparser::parsewxobject* parse(const wxstring& source) proceeds parsing of the document. this is end-user method. you can simply call it when you need to obtain parsed output (which is parser-specific) the method does these things:
you shouldn't use initparser, doparsing, getproduct or doneparser directly.
wxhtmlparser::pushtaghandlervoid pushtaghandler(wxhtmltaghandler* handler, const wxstring& tags) forces the handler to handle additional tags (not returned by getsupportedtags). the handler should already be added to this parser. parameters handler
example imagine you want to parse following pseudo-html structure:
<myitems> <param name="one" value="1"> <param name="two" value="2"> </myitems> <execute> <param program="text.exe"> </execute>it is obvious that you cannot use only one tag handler for <param> tag. instead you must use context-sensitive handlers for <param> inside <myitems> and <param> inside <execute>. this is the preferred solution:
tag_handler_begin(myitem, "myitems") tag_handler_proc(tag) { // ...something... m_parser -> pushtaghandler(this, "param"); parseinner(tag); m_parser -> poptaghandler(); // ...something... } tag_handler_end(myitem) wxhtmlparser::poptaghandlervoid poptaghandler() restores parser's state before last call to pushtaghandler.
wxhtmlparser::setfsvoid setfs(wxfilesystem *fs) sets the virtual file system that will be used to request additional files. (for example <img> tag handler requests wxfsfile with the image data.)
wxhtmlparser::stopparsingvoid stopparsing() call this function to interrupt parsing from a tag handler. no more tags will be parsed afterward. this function may only be called from wxhtmlparser::parse or any function called by it (i.e. from tag handlers).
|