2 % automatically generated by HelpGen from
3 % htmlparser.tex at 14/Mar/99 20:13:37
6 \section{\class{wxHtmlParser
}}\label{wxhtmlparser
}
8 Classes derived from this handle the
{\bf generic
} parsing of HTML documents: it scans
9 the
document and divide it into blocks of tags (where one block
10 consists of beginning and ending tag and of text between these
13 It is independent from wxHtmlWindow and can be used as stand-alone parser
14 (Julian Smart's idea of speech-only HTML viewer or wget-like utility -
15 see InetGet sample for example).
17 It uses system of tag handlers to parse the HTML
document. Tag handlers
18 are not statically shared by all instances but are created for each
19 wxHtmlParser instance. The reason is that the handler may contain
20 document-specific temporary data used during parsing (e.g. complicated
21 structures like tables).
23 Typically the user calls only the
\helpref{Parse
}{wxhtmlparserparse
} method.
25 \wxheading{Derived from
}
29 \wxheading{Include files
}
35 \helpref{wxHtml
}{librarieslist
}
39 \helpref{Cells Overview
}{cells
},
40 \helpref{Tag Handlers Overview
}{handlers
},
41 \helpref{wxHtmlTag
}{wxhtmltag
}
43 \latexignore{\rtfignore{\wxheading{Members
}}}
45 \membersection{wxHtmlParser::wxHtmlParser
}\label{wxhtmlparserwxhtmlparser
}
47 \func{}{wxHtmlParser
}{\void}
51 \membersection{wxHtmlParser::AddTag
}\label{wxhtmlparseraddtag
}
53 \func{void
}{AddTag
}{\param{const wxHtmlTag\&
}{tag
}}
55 This may (and may not) be overwritten in derived class.
57 This method is called each time new tag is about to be added.
58 {\it tag
} contains information about the tag. (See
\helpref{wxHtmlTag
}{wxhtmltag
}
61 Default (wxHtmlParser) behaviour is this:
62 First it finds a handler capable of handling this tag and then it calls
63 handler's HandleTag method.
65 \membersection{wxHtmlParser::AddTagHandler
}\label{wxhtmlparseraddtaghandler
}
67 \func{virtual void
}{AddTagHandler
}{\param{wxHtmlTagHandler
}{*handler
}}
69 Adds handler to the internal list (\& hash table) of handlers. This
70 method should not be called directly by user but rather by derived class'
73 This adds the handler to this
{\bf instance
} of wxHtmlParser, not to
74 all objects of this class! (Static front-end to AddTagHandler is provided
77 All handlers are deleted on object deletion.
79 \membersection{wxHtmlParser::AddText
}\label{wxhtmlparseraddword
}
81 \func{virtual void
}{AddWord
}{\param{const wxString\&
}{txt
}}
83 Must be overwritten in derived class.
85 This method is called by
\helpref{DoParsing
}{wxhtmlparserdoparsing
}
86 each time a part of text is parsed.
{\it txt
} is NOT only one word, it is
87 substring of input. It is not formatted or preprocessed (so white spaces are
90 \membersection{wxHtmlParser::DoParsing
}\label{wxhtmlparserdoparsing
}
92 \func{void
}{DoParsing
}{\param{int
}{begin
\_pos},
\param{int
}{end
\_pos}}
94 \func{void
}{DoParsing
}{\void}
96 Parses the m
\_Source from begin
\_pos to end
\_pos-
1.
97 (in noparams version it parses whole m
\_Source)
99 \membersection{wxHtmlParser::DoneParser
}\label{wxhtmlparserdoneparser
}
101 \func{virtual void
}{DoneParser
}{\void}
103 This must be called after DoParsing().
105 \membersection{wxHtmlParser::GetFS
}\label{wxhtmlparsergetfs
}
107 \constfunc{wxFileSystem*
}{GetFS
}{\void}
109 Returns pointer to the file system. Because each tag handler has
110 reference to it is parent parser it can easily request the file by
114 wxFSFile *f = m_Parser -> GetFS() -> OpenFile("image.jpg");
117 \membersection{wxHtmlParser::GetProduct
}\label{wxhtmlparsergetproduct
}
119 \func{virtual wxObject*
}{GetProduct
}{\void}
121 Returns product of parsing. Returned value is result of parsing
122 of the
document. The type of this result depends on internal
123 representation in derived parser (but it must be derived from wxObject!).
125 See wxHtmlWinParser for details.
127 \membersection{wxHtmlParser::GetSource
}\label{wxhtmlparsergetsource
}
129 \func{wxString*
}{GetSource
}{\void}
131 Returns pointer to the source being parsed.
134 \membersection{wxHtmlParser::InitParser
}\label{wxhtmlparserinitparser
}
136 \func{virtual void
}{InitParser
}{\param{const wxString\&
}{source
}}
138 Setups the parser for parsing the
{\it source
} string. (Should be overridden
141 \membersection{wxHtmlParser::OpenURL
}\label{wxhtmlparseropenurl
}
143 \func{virtual wxFSFile*
}{OpenURL
}{\param{wxHtmlURLType
}{type
},
\param{const wxString\&
}{url
}}
145 Opens given URL and returns
{\tt wxFSFile
} object that can be used to read data
146 from it. This method may return NULL in one of two cases: either the URL doesn't
147 point to any valid resource or the URL is blocked by overridden implementation
148 of
{\it OpenURL
} in derived class.
150 \wxheading{Parameters
}
152 \docparam{type
}{Indicates type of the resource. Is one of:
154 \begin{twocollist
}\itemsep=
0pt
155 \twocolitem{{\bf wxHTML
\_URL\_PAGE}}{Opening a HTML page.
}
156 \twocolitem{{\bf wxHTML
\_URL\_IMAGE}}{Opening an image.
}
157 \twocolitem{{\bf wxHTML
\_URL\_OTHER}}{Opening a resource that doesn't fall into
161 \docparam{url
}{URL being opened.
}
165 Always use this method in tag handlers instead of
{\tt GetFS()->OpenFile()
}
166 because it can block the URL and is thus more secure.
168 Default behaviour is to call
\helpref{wxHtmlWindow::OnOpeningURL
}{wxhtmlwindowonopeningurl
}
169 of the associated wxHtmlWindow object (which may decide to block the URL or
170 redirect it to another one),if there's any, and always open the URL if the
171 parser is not used with wxHtmlWindow.
173 Returned
{\tt wxFSFile
} object is not guaranteed to point to
{\it url
}, it might
174 have been redirected!
176 \membersection{wxHtmlParser::Parse
}\label{wxhtmlparserparse
}
178 \func{wxObject*
}{Parse
}{\param{const wxString\&
}{source
}}
180 Proceeds parsing of the
document. This is end-user method. You can simply
181 call it when you need to obtain parsed output (which is parser-specific)
183 The method does these things:
185 \begin{enumerate
}\itemsep=
0pt
186 \item calls
\helpref{InitParser(source)
}{wxhtmlparserinitparser
}
187 \item calls
\helpref{DoParsing
}{wxhtmlparserdoparsing
}
188 \item calls
\helpref{GetProduct
}{wxhtmlparsergetproduct
}
189 \item calls
\helpref{DoneParser
}{wxhtmlparserdoneparser
}
190 \item returns value returned by GetProduct
193 You shouldn't use InitParser, DoParsing, GetProduct or DoneParser directly.
195 \membersection{wxHtmlParser::PushTagHandler
}\label{wxhtmlparserpushtaghandler
}
197 \func{void
}{PushTagHandler
}{\param{wxHtmlTagHandler*
}{handler
},
\param{const wxString\&
}{tags
}}
199 Forces the handler to handle additional tags
200 (not returned by
\helpref{GetSupportedTags
}{wxhtmltaghandlergetsupportedtags
}).
201 The handler should already be added to this parser.
203 \wxheading{Parameters
}
205 \docparam{handler
}{the handler
}
206 \docparam{tags
}{List of tags (in same format as GetSupportedTags's return value). The parser
207 will redirect these tags to
{\it handler
} (until call to
\helpref{PopTagHandler
}{wxhtmlparserpoptaghandler
}).
}
211 Imagine you want to parse following pseudo-html structure:
215 <param name="one" value="
1">
216 <param name="two" value="
2">
220 <param program="text.exe">
224 It is obvious that you cannot use only one tag handler for <param> tag.
225 Instead you must use context-sensitive handlers for <param> inside <myitems>
226 and <param> inside <execute>.
228 This is the preferred solution:
231 TAG_HANDLER_BEGIN(MYITEM, "MYITEMS")
232 TAG_HANDLER_PROC(tag)
236 m_Parser -> PushTagHandler(this, "PARAM");
238 m_Parser -> PopTagHandler();
242 TAG_HANDLER_END(MYITEM)
246 \membersection{wxHtmlParser::PopTagHandler
}\label{wxhtmlparserpoptaghandler
}
248 \func{void
}{PopTagHandler
}{\void}
250 Restores parser's state before last call to
251 \helpref{PushTagHandler
}{wxhtmlparserpushtaghandler
}.
254 \membersection{wxHtmlParser::SetFS
}\label{wxhtmlparsersetfs
}
256 \func{void
}{SetFS
}{\param{wxFileSystem
}{*fs
}}
258 Sets the virtual file system that will be used to request additional
259 files. (For example
{\tt <IMG>
} tag handler requests wxFSFile with the
262 \membersection{wxHtmlParser::StopParsing
}\label{wxhtmlparserstopparsing
}
264 \func{void
}{StopParsing
}{\void}
266 Call this function to interrupt parsing from a tag handler. No more tags
267 will be parsed afterward. This function may only be called from
268 \helpref{wxHtmlParser::Parse
}{wxhtmlparserparse
} or any function called
269 by it (i.e. from tag handlers).