HtmlToXml Delphi DLL Reference Documentation

HtmlToXml

Current Version: 11.5.0

Chilkat.HtmlToXml

Convert HTML into well-formed XML for structured parsing and searching.

Chilkat.HtmlToXml converts HTML into well-formed XML so the content can be parsed, searched, transformed, or processed programmatically with XML tools. It can accept HTML from strings, files, byte arrays, BinData, or StringBuilder, and provides options for dropping selected tags, removing common text-formatting tags, controlling non-breaking spaces, choosing the XML charset, and saving the converted XML to a file.

HTML to XML conversion

Convert real-world HTML into well-formed XML that can be loaded into Chilkat.Xml or other XML processing tools.

Flexible input sources

Supply HTML from strings, files, byte arrays, BinData, or StringBuilder depending on how the content is received or built.

Drop selected tags

Remove specific tag types from the output when the application wants a cleaner XML result focused on relevant content.

Text-formatting cleanup

Drop common formatting tags when the structure matters more than visual presentation.

NBSP handling

Control how non-breaking spaces are represented, converted, removed, or preserved in the XML output.

Charset and file output

Choose the XML charset and write the converted XML directly to a file when a persisted result is needed.

Common pattern: Load or assign the HTML, set any cleanup options such as dropped tags, text-formatting removal, Nbsp behavior, and XmlCharset, then call the conversion method and parse the result as XML. Use HtmlToXml when structured extraction is needed; use HtmlToText when the goal is readable plain text.

Create/Dispose

var
myObject: HCkHtmlToXml;

begin
myObject := CkHtmlToXml_Create();

// ...

CkHtmlToXml_Dispose(myObject);
end;
function CkHtmlToXml_Create: HCkHtmlToXml; stdcall;

Creates an instance of the HCkHtmlToXml object and returns a handle (i.e. a Pointer). The handle is passed in the 1st argument for the functions listed on this page.

procedure CkHtmlToXml_Dispose(handle: HCkHtmlToXml); stdcall;

Objects created by calling CkHtmlToXml_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.

Properties

DebugLogFilePath
procedure CkHtmlToXml_getDebugLogFilePath(objHandle: HCkHtmlToXml; outPropVal: HCkString); stdcall;
procedure CkHtmlToXml_putDebugLogFilePath(objHandle: HCkHtmlToXml; newPropVal: PWideChar); stdcall;
function CkHtmlToXml__debugLogFilePath(objHandle: HCkHtmlToXml): PWideChar; stdcall;

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top
DropCustomTags
function CkHtmlToXml_getDropCustomTags(objHandle: HCkHtmlToXml): wordbool; stdcall;
procedure CkHtmlToXml_putDropCustomTags(objHandle: HCkHtmlToXml; newPropVal: wordbool); stdcall;

Controls whether tags that Chilkat does not recognize as standard HTML elements are omitted from the generated XML.

When to use: Set this property to True when custom or application-specific tags would add noise to the XML structure. Leave it False when those tags are meaningful to the application and should remain represented in the converted output.

top
Html
procedure CkHtmlToXml_getHtml(objHandle: HCkHtmlToXml; outPropVal: HCkString); stdcall;
procedure CkHtmlToXml_putHtml(objHandle: HCkHtmlToXml; newPropVal: PWideChar); stdcall;
function CkHtmlToXml__html(objHandle: HCkHtmlToXml): PWideChar; stdcall;

The HTML source to be converted. Set this property to an HTML string, configure any conversion options, and then call ToXml, Xml, or ToXmlSb.

Assigning this property replaces the current in-memory HTML source. For file-to-file conversion, use ConvertFile. To load HTML from a file, BinData, or StringBuilder, use the corresponding SetHtml* method.

HTML input does not need to already be valid XML. The converter is intended for real-world HTML and repairs markup as needed to produce a well-formed XML document. Chilkat examples show malformed HTML being normalized and ordinary text represented in <text> elements to simplify programmatic extraction.

See the notes about PWideChar memory ownership and validity.

top
LastErrorHtml
procedure CkHtmlToXml_getLastErrorHtml(objHandle: HCkHtmlToXml; outPropVal: HCkString); stdcall;
function CkHtmlToXml__lastErrorHtml(objHandle: HCkHtmlToXml): PWideChar; stdcall;

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

See the notes about PWideChar memory ownership and validity.

top
LastErrorText
procedure CkHtmlToXml_getLastErrorText(objHandle: HCkHtmlToXml; outPropVal: HCkString); stdcall;
function CkHtmlToXml__lastErrorText(objHandle: HCkHtmlToXml): PWideChar; stdcall;

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

See the notes about PWideChar memory ownership and validity.

top
LastErrorXml
procedure CkHtmlToXml_getLastErrorXml(objHandle: HCkHtmlToXml; outPropVal: HCkString); stdcall;
function CkHtmlToXml__lastErrorXml(objHandle: HCkHtmlToXml): PWideChar; stdcall;

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

See the notes about PWideChar memory ownership and validity.

top
LastMethodSuccess
function CkHtmlToXml_getLastMethodSuccess(objHandle: HCkHtmlToXml): wordbool; stdcall;
procedure CkHtmlToXml_putLastMethodSuccess(objHandle: HCkHtmlToXml; newPropVal: wordbool); stdcall;

Indicates the success or failure of the most recent method call: True means success, False means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
Nbsp
function CkHtmlToXml_getNbsp(objHandle: HCkHtmlToXml): Integer; stdcall;
procedure CkHtmlToXml_putNbsp(objHandle: HCkHtmlToXml; newPropVal: Integer); stdcall;

Controls how HTML non-breaking-space entities are handled during conversion. The default value is 0.

ValueBehavior for &nbsp;
0Convert to a normal space character (U+0020).
1Convert to the numeric character reference &#160; (U+00A0).
2Drop the non-breaking-space entity.
3Leave the &nbsp; entity unconverted by this option.

This setting applies specifically to the HTML entity &nbsp;; it does not define general whitespace normalization.

top
VerboseLogging
function CkHtmlToXml_getVerboseLogging(objHandle: HCkHtmlToXml): wordbool; stdcall;
procedure CkHtmlToXml_putVerboseLogging(objHandle: HCkHtmlToXml; newPropVal: wordbool); stdcall;

If set to True, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is False. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
procedure CkHtmlToXml_getVersion(objHandle: HCkHtmlToXml; outPropVal: HCkString); stdcall;
function CkHtmlToXml__version(objHandle: HCkHtmlToXml): PWideChar; stdcall;

Version of the component/library, such as "10.1.0"

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top
XmlCharset
procedure CkHtmlToXml_getXmlCharset(objHandle: HCkHtmlToXml; outPropVal: HCkString); stdcall;
procedure CkHtmlToXml_putXmlCharset(objHandle: HCkHtmlToXml; newPropVal: PWideChar); stdcall;
function CkHtmlToXml__xmlCharset(objHandle: HCkHtmlToXml): PWideChar; stdcall;

Specifies the character encoding to identify for the generated XML, such as utf-8 or iso-8859-1. If this property is empty, Chilkat uses the character encoding of the HTML input. Otherwise, the converted XML uses the specified charset.

String versus file output: A string returned by ToXml or Xml is a string in the programming language's native string representation, while the XML declaration reflects XmlCharset. When writing that string to a file, use the same charset so the file bytes agree with the XML declaration. ConvertFile performs the file conversion directly.

See the notes about PWideChar memory ownership and validity.

top

Methods

ConvertFile
function CkHtmlToXml_ConvertFile(objHandle: HCkHtmlToXml;
    inHtmlPath: PWideChar;
    destXmlPath: PWideChar): wordbool; stdcall;

Converts the HTML file at inHtmlPath to a well-formed XML file at destXmlPath. The output encoding is controlled by XmlCharset; if XmlCharset is empty, Chilkat uses the HTML source encoding.

Returns True on success and False on failure.

Conversion behavior: The input is parsed as HTML rather than XML. Chilkat can normalize malformed or incomplete HTML markup as part of producing a well-formed XML document suitable for subsequent parsing and data extraction.

Returns True for success, False for failure.

top
DropTagType
procedure CkHtmlToXml_DropTagType(objHandle: HCkHtmlToXml;
    tagName: PWideChar) stdcall;

Marks the specified HTML tag type to be dropped from the generated XML. To drop multiple tag types, call this method once for each tag name.

The setting remains in effect for subsequent conversions performed by this HtmlToXml object. Use UndropTagType to reverse the setting for a particular tag type.

top
DropTextFormattingTags
procedure CkHtmlToXml_DropTextFormattingTags(objHandle: HCkHtmlToXml) stdcall;

Configures the converter to drop common text-formatting tags from the generated XML. The affected tag names are:

b, font, i, u, br, center, em, strong, big, tt, s, small, strike, sub, and sup.

This is useful when the formatting markup is not relevant to later XML parsing and the application wants a simpler structural representation. Call UndropTextFormattingTags to keep these tags instead.

More Information and Examples
top
SetHtmlBd
function CkHtmlToXml_SetHtmlBd(objHandle: HCkHtmlToXml;
    bd: HCkBinData): wordbool; stdcall;
Introduced in version 9.5.0.77

Replaces the current HTML source with the complete contents of bd.

The data is copied from the supplied BinData object and becomes the input for a later call to ToXml, Xml, or ToXmlSb. Returns True on success and False on failure.

Returns True for success, False for failure.

More Information and Examples
top
SetHtmlFromFile
function CkHtmlToXml_SetHtmlFromFile(objHandle: HCkHtmlToXml;
    filename: PWideChar): wordbool; stdcall;

Loads HTML from filename and replaces the current Html input with the file contents.

Returns True on success and False if the file cannot be read or the HTML input cannot be loaded. Call ToXml, Xml, or ToXmlSb afterward to perform the conversion.

Returns True for success, False for failure.

top
SetHtmlSb
function CkHtmlToXml_SetHtmlSb(objHandle: HCkHtmlToXml;
    sb: HCkStringBuilder): wordbool; stdcall;
Introduced in version 9.5.0.97

Replaces the current HTML source with the complete contents of sb.

The text is copied from the supplied StringBuilder and becomes the input for a later call to ToXml, Xml, or ToXmlSb. Returns True on success and False on failure.

Returns True for success, False for failure.

top
ToXml
function CkHtmlToXml_ToXml(objHandle: HCkHtmlToXml;
    outStr: HCkString): wordbool; stdcall;
function CkHtmlToXml__toXml(objHandle: HCkHtmlToXml): PWideChar; stdcall;

Converts the current Html input to well-formed XML and returns the XML string. The generated XML uses the conversion settings currently configured on this object, including DropCustomTags, dropped tag types, Nbsp, and XmlCharset.

HTML normalization: The input is parsed as HTML, so it does not need to already be well-formed XML. Chilkat can repair incomplete or malformed markup. The generated document is wrapped in a root element, and Chilkat represents ordinary text content in <text> elements to make extraction with XML tools straightforward.

Returns True for success, False for failure.

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top
ToXmlSb
function CkHtmlToXml_ToXmlSb(objHandle: HCkHtmlToXml;
    sb: HCkStringBuilder): wordbool; stdcall;
Introduced in version 9.5.0.77

Converts the current Html input to well-formed XML and appends the generated XML to sb.

Returns True on success and False on failure. Because the result is appended, clear the destination StringBuilder first when replacement rather than concatenation is desired.

Returns True for success, False for failure.

More Information and Examples
top
UndropTagType
procedure CkHtmlToXml_UndropTagType(objHandle: HCkHtmlToXml;
    tagName: PWideChar) stdcall;

Reverses a previous DropTagType setting for the specified tag name so that tag type is no longer intentionally dropped from subsequent XML output.

This affects only the named tag type. Other tag types previously configured to be dropped remain unchanged.

top
UndropTextFormattingTags
procedure CkHtmlToXml_UndropTextFormattingTags(objHandle: HCkHtmlToXml) stdcall;

Configures the converter to retain the common text-formatting tags that are otherwise dropped by default:

b, font, i, u, br, center, em, strong, big, tt, s, small, strike, sub, and sup.

Call DropTextFormattingTags to return to dropping these formatting tags.

More Information and Examples
top
Xml
function CkHtmlToXml_Xml(objHandle: HCkHtmlToXml;
    outStr: HCkString): wordbool; stdcall;
function CkHtmlToXml__xml(objHandle: HCkHtmlToXml): PWideChar; stdcall;

Equivalent to ToXml. Converts the current Html input to well-formed XML and returns the XML string using the object's current conversion settings.

This method is provided as an alternate name for ToXml; it does not perform a different conversion.

Returns True for success, False for failure.

See the notes about PWideChar memory ownership and validity.

top

Deprecated

ReadFile Deprecated
function CkHtmlToXml_ReadFile(objHandle: HCkHtmlToXml;
    path: PWideChar;
    outBytes: HCkByteData): wordbool; stdcall;
This method is deprecated.

Reads the complete contents of path and returns the file data as bytes.

Deprecated: This convenience method is retained for compatibility with older code. New code can use the application's normal file I/O or a Chilkat binary-data class when binary file contents are needed.

Returns True for success, False for failure.

top
ReadFileToString
function CkHtmlToXml_ReadFileToString(objHandle: HCkHtmlToXml;
    filename: PWideChar;
    srcCharset: PWideChar;
    outStr: HCkString): wordbool; stdcall;
function CkHtmlToXml__readFileToString(objHandle: HCkHtmlToXml;
    filename: PWideChar;
    srcCharset: PWideChar): PWideChar; stdcall;
This method is deprecated.

Reads the complete text file at filename and decodes its bytes using srcCharset, such as utf-8 or iso-8859-1. Returns the decoded text string.

Deprecated: This convenience method is retained for compatibility with older code. It is separate from HTML-to-XML conversion; calling it does not set the Html property or perform a conversion.

Returns True for success, False for failure.

See the notes about PWideChar memory ownership and validity.

top
SetHtmlBytes Deprecated
procedure CkHtmlToXml_SetHtmlBytes(objHandle: HCkHtmlToXml;
    inData: HCkByteData) stdcall;

Replaces the current HTML source with the contents of inData.

This method sets the input to be used by a later call to ToXml, Xml, or ToXmlSb; it does not perform the conversion itself.

top
WriteFile Deprecated
function CkHtmlToXml_WriteFile(objHandle: HCkHtmlToXml;
    path: PWideChar;
    fileData: HCkByteData): wordbool; stdcall;
This method is deprecated.

Writes the bytes in fileData to path. Returns True on success and False on failure.

Deprecated: This is a general file-writing convenience method and is retained for compatibility with older code; it is not specific to HTML-to-XML conversion.

Returns True for success, False for failure.

top
WriteStringToFile
function CkHtmlToXml_WriteStringToFile(objHandle: HCkHtmlToXml;
    stringToWrite: PWideChar;
    filename: PWideChar;
    charset: PWideChar): wordbool; stdcall;
This method is deprecated.

Encodes stringToWrite using charset and writes the resulting text to filename. Typical charset names include utf-8 and iso-8859-1.

Returns True on success and False on failure.

Deprecated: This convenience method is retained for compatibility with older code. If it is used to save the string returned by ToXml, use a charset that agrees with the XML declaration, normally the same value configured in XmlCharset.

Returns True for success, False for failure.

top