|
||||||||||||||||||||
HtmlZap DocumentationMost programs that use the HtmlZap control will probably follow this basic algorithm:
HtmlZap Properties and Methods
Property ClosedTag
This property will be true when the current tag is a "singleton" tag
as found in XML and XHMTL, e.g., Property CompressWS
If you set this property to True, HtmlZap will compress runs of multiple whitespace characters (tabs, spaces, carriage returns, etc.) to a single space. This is most useful if you're interpreting the HTML for display; browsers do the same thing. It's best to leave this property set to False if you're planning on writing out modified HTML code: the extra whitespace will make the resulting file much more legible. Property EOF
This boolean value changes to True when the last slice has been read from the source HTML file. Property HdrLevel
Indicates that the current slice is a Property IsTag
Indicates that the current slice is a tag. The tag's name is available
from the If this property is False, the current slice is text, which can be
retrieved using the Method Load
Loads an HTML file for processing. The control executes the Assuming the load operation is successful, the control's properties will
reflect the nature of the first "slice" in the HTML file. If the load fails,
the control will throw an error. In Visual Basic, you can examine the Note: The HtmlZap control will keep the loaded file open until the
Technical Note: For those who may be concerned, HtmlZap doesn't actually read the file during the Load operation. The control uses a memory-mapped file to process the HTML, so "nothing much" actually happens while the Load method is executing. The method just sets up the mapped file and initializes the control to the first slice. Method LoadBuffer
Loads HTML file for processing from a Byte Array or String. The control
executes the Assuming the load operation is successful, the control's properties will
reflect the nature of the first "slice" in the HTML file. If the load fails,
the control will throw an error. In Visual Basic, you can examine the This method is designed for use with ActiveX Web objects. Specifically,
you can use the For example, if you execute a VB statement like this: AsyncRead "http://poit.narf.org/brain/index.htm", vbAsyncTypeByteArray you'll need an event handler that looks something like this (assuming your HtmlZap control is called "HZ"): Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty) ' ' File read completed ' Dim es As Integer On Error Resume Next HZ.LoadBuffer AsyncProp.Value es = Err On Error GoTo 0 If es <> 0 Then ' HTTP transfer or LoadBuffer method failed {error handling} Exit Sub End If While Not HZ.EOF {process the HTML} HZ.Next Wend HZ.Reset End Sub The contents of Property MaxParam
Reads the number of parameters for the current tag. Returns 0 for text slices or if the current tag has no parameters. To display all the current tag's parameter names and values on the Debug window, you might do something like this: Dim n As Integer, nmax As Integer nmax = HZ.MaxParam - 1 For n = 0 To nmax Debug.Print HZ.PName(n); "="; HZ.PValue(n) Next n Method Next
Moves on to the next slice in the HTML file. Sets all the parameters to
reflect the new slice; the Property Param
Retrieves or sets a tag parameter by its name. For example, if you were
processing an Debug.Print "Image File is "; HZ.Param("src") This will retrieve the You can also use the <a href="http://www.yahoo.com/> and you executed the statements: hz.Param("href") = "http://www.google.com/" hz.Param("target") = "_new" the a href="http://www.google.com/" target="_new" Note that (for historical reasons) the toString property returns the tag without the enclosing <> brackets. Property Percent
Indicates progress through the current HTML file in percent. Good for progress bars, etc. Property PName
Retrieves a parameter name from the current tag by its index. Parameter
indexes range from 0 to For example, for the tag: <img src="pinky.gif" width=100 height=200> You'd get (
Property Position
Retrieves or sets position in the file in bytes from the beginning of the file. Can be used to save and restore positions if you need to jump forward or backwards in the file. Property PValue
Retrieves a parameter value from the current tag by its index. Parameter
indexes range from 0 to See the Method RemoveParam
Removes the parameter indicated by paramNameString from the
current tag. After you remove a parameter you can retrieve the modified tag
with the Method Reset
Closes the current HTML file, frees memory, clears properties, and so forth. Returns the control to its initial state, ready to process another file. Method Rewind
Sets the control back to the beginning of the current file. Property TagName
Returns the name of the current tag (e.g., "h", "p", "img", etc.). Tag names are always converted to lower case. Returns the empty string if the current slice is text.
Property Text
Returns text found between tags when the current slice is text ( Property ToString
Returns the current tag and all parameters in string form, without leading and trailing <>'s. Take a look at the sample source code to see how this property is used. You can use this property to retrieve the current version of of the
current tag at any time, whether you have modified it (using the Property URLCanonicalize
Converts a URL to canonical form, optionally escaping "non-URL-safe"
characters (if escapeFlag is nonzero). This is just a wrapper around
the OS function For more information consult the Microsoft documentation. Property URLCombine
Combines a base and a relative URL, optionally escaping
"non-URL-safe" characters (if escapeFlag is nonzero). This is just a
wrapper around the OS function For more information consult the Microsoft documentation. Last revised: 26 January 2013 |