---
product: Chilkat
product_version: 11.7.0
language: sqlserver
language_label: SQL Server
class: HtmlToXml
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/sqlserver_HtmlToXmlRef.html
---
# Chilkat HtmlToXml — SQL Server — v11.7.0

> Chilkat 11.7.0 · language=sqlserver · class=HtmlToXml
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/HtmlToXml.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/sqlserver/guide.md`.

## Purpose

**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.

For an extended overview, see [HtmlToXml Class Overview](https://www.chilkatsoft.com/htmltoxml_class_overview.asp).

## Object creation, unlocking and error handling

**Object Creation**

```sql
DECLARE @hr int
DECLARE @htmlToXml int
EXEC @hr = sp_OACreate 'Chilkat.HtmlToXml', @htmlToXml OUT
IF @hr <> 0
BEGIN
    PRINT 'Failed to create ActiveX component'
    RETURN
END

-- ... use @htmlToXml ...

EXEC @hr = sp_OADestroy @htmlToXml
```

T-SQL uses the Chilkat ActiveX through the OLE Automation stored procedures. They must be enabled once on the server (`EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE;`), and the Chilkat ActiveX registered must match the bitness of the SQL Server instance (64-bit for a 64-bit SQL Server). To bind to a specific major version of Chilkat, append the major version number to the ProgID, such as `sp_OACreate 'Chilkat.HtmlToXml.11'` for Chilkat v11.\*.\*.

`sp_OACreate` returns an object token (an `int`) that is passed as the first argument of every `sp_OAMethod`, `sp_OAGetProperty` and `sp_OASetProperty` call, and released with `sp_OADestroy`. Objects returned by methods (such as an `HttpResponse` or `JsonObject`) are also tokens received through an `int` OUT parameter; they must likewise be destroyed, and the OUT parameter is `NULL` when the method fails to return an object. Objects passed as arguments are passed by their token. When an OLE Automation procedure itself fails (non-zero `@hr`), `sp_OAGetErrorInfo` describes the error.

Data types: strings are `nvarchar(4000)`; integers, booleans (1 or 0) and object tokens are `int`; dates are `datetime`. In the signatures on this page, `@success`, `@iResult`, `@sResult` and the like are the OUT variables receiving a method's return value, `@iValue` / `@sValue` receive or supply a property value, and the remaining `@` variables are the method's arguments in order.

A string returned through an OUT parameter is limited to 4000 characters. For longer values, retrieve the result as a result set into a table variable instead of an OUT parameter, for example `DECLARE @tmp TABLE (outputLine ntext)` followed by `INSERT INTO @tmp EXEC sp_OAGetProperty @htmlToXml, 'LastErrorText'`. See [string length limitations for strings returned by sp_OAMethod calls](https://www.chilkatsoft.com/sql_server_nvarchar_max_limitation.asp).

Methods that pass or return raw byte arrays are not shown on this page, because `varbinary(max)` values cannot be exchanged through `sp_OAMethod` (see [varbinary(max) limitation](https://www.chilkatsoft.com/sql_server_varbinary_max_limitation.asp)). Use the `BinData`-based alternatives (methods ending in *Bd*) or the base64 / hex string-encoded variants instead. Binary *properties* (such as `LastBinaryResult`) can be retrieved as a result set into a table variable, as shown in their signatures. Asynchronous (*\*Async*) methods and event callbacks are not available from SQL Server.

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in SQL Server.

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `EXEC sp_OAGetProperty @htmlToXml, 'DebugLogFilePath', @sValue OUT EXEC sp_OASetProperty @htmlToXml, 'DebugLogFilePath', @sValue` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastBinaryResult` | `INSERT INTO @tmp EXEC sp_OAGetProperty @htmlToXml, 'LastBinaryResult'` | read-only | This property is mainly used in SQL Server stored procedures to retrieve binary data from the last method call that returned binary data. |
| `LastErrorHtml` | `EXEC sp_OAGetProperty @htmlToXml, 'LastErrorHtml', @sValue OUT` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `EXEC sp_OAGetProperty @htmlToXml, 'LastErrorText', @sValue OUT` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `EXEC sp_OAGetProperty @htmlToXml, 'LastErrorXml', @sValue OUT` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `EXEC sp_OAGetProperty @htmlToXml, 'LastMethodSuccess', @iValue OUT EXEC sp_OASetProperty @htmlToXml, 'LastMethodSuccess', @iValue` | read/write | Indicates the success or failure of the most recent method call: `1` means success, `0` means failure. |
| `LastStringResult` | `EXEC sp_OAGetProperty @htmlToXml, 'LastStringResult', @sValue OUT` | read-only | In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. |
| `LastStringResultLen` | `EXEC sp_OAGetProperty @htmlToXml, 'LastStringResultLen', @iValue OUT` | read-only | The length, in characters, of the string contained in the LastStringResult property. |
| `VerboseLogging` | `EXEC sp_OAGetProperty @htmlToXml, 'VerboseLogging', @iValue OUT EXEC sp_OASetProperty @htmlToXml, 'VerboseLogging', @iValue` | read/write | If set to `1`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `EXEC sp_OAGetProperty @htmlToXml, 'Version', @sValue OUT` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `DropCustomTags` | property, read/write | `EXEC sp_OAGetProperty @htmlToXml, 'DropCustomTags', @iValue OUT EXEC sp_OASetProperty @htmlToXml, 'DropCustomTags', @iValue` |
| `Html` | property, read/write | `EXEC sp_OAGetProperty @htmlToXml, 'Html', @sValue OUT EXEC sp_OASetProperty @htmlToXml, 'Html', @sValue` |
| `Nbsp` | property, read/write | `EXEC sp_OAGetProperty @htmlToXml, 'Nbsp', @iValue OUT EXEC sp_OASetProperty @htmlToXml, 'Nbsp', @iValue` |
| `XmlCharset` | property, read/write | `EXEC sp_OAGetProperty @htmlToXml, 'XmlCharset', @sValue OUT EXEC sp_OASetProperty @htmlToXml, 'XmlCharset', @sValue` |
| `ConvertFile` | method | `EXEC sp_OAMethod @htmlToXml, 'ConvertFile', @success OUT, @inHtmlPath, @destXmlPath` |
| `DropTagType` | method | `EXEC sp_OAMethod @htmlToXml, 'DropTagType', NULL, @tagName` |
| `DropTextFormattingTags` | method | `EXEC sp_OAMethod @htmlToXml, 'DropTextFormattingTags', NULL` |
| `SetHtmlBd` | method | `EXEC sp_OAMethod @htmlToXml, 'SetHtmlBd', @success OUT, @bd` |
| `SetHtmlFromFile` | method | `EXEC sp_OAMethod @htmlToXml, 'SetHtmlFromFile', @success OUT, @filename` |
| `SetHtmlSb` | method | `EXEC sp_OAMethod @htmlToXml, 'SetHtmlSb', @success OUT, @sb` |
| `ToXml` | method | `EXEC sp_OAMethod @htmlToXml, 'ToXml', @sResult OUT` |
| `ToXmlSb` | method | `EXEC sp_OAMethod @htmlToXml, 'ToXmlSb', @success OUT, @sb` |
| `UndropTagType` | method | `EXEC sp_OAMethod @htmlToXml, 'UndropTagType', NULL, @tagName` |
| `UndropTextFormattingTags` | method | `EXEC sp_OAMethod @htmlToXml, 'UndropTextFormattingTags', NULL` |

Deprecated members are listed at the end of this file with their replacements; do not use them in new code.

## Properties

### HtmlToXml.DropCustomTags

`Chilkat 11.7.0 · sqlserver · HtmlToXml · DropCustomTags · property · read/write`

```sql
EXEC sp_OAGetProperty @htmlToXml, 'DropCustomTags', @iValue OUT
EXEC sp_OASetProperty @htmlToXml, 'DropCustomTags', @iValue
```

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 `1` when custom or application-specific tags would add noise to the XML structure. Leave it `0` when those tags are meaningful to the application and should remain represented in the converted output.

### HtmlToXml.Html

`Chilkat 11.7.0 · sqlserver · HtmlToXml · Html · property · read/write`

```sql
EXEC sp_OAGetProperty @htmlToXml, 'Html', @sValue OUT
EXEC sp_OASetProperty @htmlToXml, 'Html', @sValue
```

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.

### HtmlToXml.Nbsp

`Chilkat 11.7.0 · sqlserver · HtmlToXml · Nbsp · property · read/write`

```sql
EXEC sp_OAGetProperty @htmlToXml, 'Nbsp', @iValue OUT
EXEC sp_OASetProperty @htmlToXml, 'Nbsp', @iValue
```

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

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

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

### HtmlToXml.XmlCharset

`Chilkat 11.7.0 · sqlserver · HtmlToXml · XmlCharset · property · read/write`

```sql
EXEC sp_OAGetProperty @htmlToXml, 'XmlCharset', @sValue OUT
EXEC sp_OASetProperty @htmlToXml, 'XmlCharset', @sValue
```

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.

## Methods

### HtmlToXml.ConvertFile

`Chilkat 11.7.0 · sqlserver · HtmlToXml · ConvertFile · method`

```sql
EXEC sp_OAMethod @htmlToXml, 'ConvertFile', @success OUT, @inHtmlPath, @destXmlPath
```

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 `1` on success and `0` 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 1 for success, 0 for failure.

### HtmlToXml.DropTagType

`Chilkat 11.7.0 · sqlserver · HtmlToXml · DropTagType · method`

```sql
EXEC sp_OAMethod @htmlToXml, 'DropTagType', NULL, @tagName
```

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.

### HtmlToXml.DropTextFormattingTags

`Chilkat 11.7.0 · sqlserver · HtmlToXml · DropTextFormattingTags · method`

```sql
EXEC sp_OAMethod @htmlToXml, 'DropTextFormattingTags', NULL
```

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.

### HtmlToXml.SetHtmlBd

`Chilkat 11.7.0 · sqlserver · HtmlToXml · SetHtmlBd · method · since 9.5.0.77`

```sql
EXEC sp_OAMethod @htmlToXml, 'SetHtmlBd', @success OUT, @bd
```

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 `1` on success and `0` on failure.

Returns 1 for success, 0 for failure.

### HtmlToXml.SetHtmlFromFile

`Chilkat 11.7.0 · sqlserver · HtmlToXml · SetHtmlFromFile · method`

```sql
EXEC sp_OAMethod @htmlToXml, 'SetHtmlFromFile', @success OUT, @filename
```

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

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

Returns 1 for success, 0 for failure.

### HtmlToXml.SetHtmlSb

`Chilkat 11.7.0 · sqlserver · HtmlToXml · SetHtmlSb · method · since 9.5.0.97`

```sql
EXEC sp_OAMethod @htmlToXml, 'SetHtmlSb', @success OUT, @sb
```

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 `1` on success and `0` on failure.

Returns 1 for success, 0 for failure.

### HtmlToXml.ToXml

`Chilkat 11.7.0 · sqlserver · HtmlToXml · ToXml · method`

```sql
EXEC sp_OAMethod @htmlToXml, 'ToXml', @sResult OUT
```

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 `NULL` on failure

### HtmlToXml.ToXmlSb

`Chilkat 11.7.0 · sqlserver · HtmlToXml · ToXmlSb · method · since 9.5.0.77`

```sql
EXEC sp_OAMethod @htmlToXml, 'ToXmlSb', @success OUT, @sb
```

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

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

Returns 1 for success, 0 for failure.

### HtmlToXml.UndropTagType

`Chilkat 11.7.0 · sqlserver · HtmlToXml · UndropTagType · method`

```sql
EXEC sp_OAMethod @htmlToXml, 'UndropTagType', NULL, @tagName
```

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.

### HtmlToXml.UndropTextFormattingTags

`Chilkat 11.7.0 · sqlserver · HtmlToXml · UndropTextFormattingTags · method`

```sql
EXEC sp_OAMethod @htmlToXml, 'UndropTextFormattingTags', NULL
```

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.

## Deprecated members — do not use in new code

| Member | Kind | Deprecated in | Use instead |
|---|---|---|---|
| `ReadFileToString` | method | before 11.6.1 | — |
| `WriteStringToFile` | method | before 11.6.1 | — |

## Related classes

[`BinData`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/sqlserver/classes/BinData.md), [`StringBuilder`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/sqlserver/classes/StringBuilder.md)

