---
product: Chilkat
product_version: 11.7.0
language: wc
language_label: Unicode C
class: HtmlToXml
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/wc_CkHtmlToXmlWRef.html
---
# Chilkat HtmlToXml — Unicode C — v11.7.0

> Chilkat 11.7.0 · language=wc · 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/wc/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

**Create/Dispose**

```c
HCkHtmlToXmlW instance = CkHtmlToXmlW_Create();
// ...
CkHtmlToXmlW_Dispose(instance);
```

`HCkHtmlToXmlW CkHtmlToXmlW_Create(void);`

Creates an instance of the HCkHtmlToXmlW object and returns a handle ("void \*" pointer). The handle is passed in the 1st argument for the functions listed on this page.

`void CkHtmlToXmlW_Dispose(HCkHtmlToXmlW handle);`

Objects created by calling CkHtmlToXmlW_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkHtmlToXmlW_Dispose.

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 Unicode C.

## 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` | `void CkHtmlToXmlW_getDebugLogFilePath(HCkHtmlToXmlW cHandle, HCkString retval); void CkHtmlToXmlW_putDebugLogFilePath(HCkHtmlToXmlW cHandle, const wchar_t *newVal); const wchar_t *CkHtmlToXmlW_debugLogFilePath(HCkHtmlToXmlW cHandle);` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastErrorHtml` | `void CkHtmlToXmlW_getLastErrorHtml(HCkHtmlToXmlW cHandle, HCkString retval); const wchar_t *CkHtmlToXmlW_lastErrorHtml(HCkHtmlToXmlW cHandle);` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `void CkHtmlToXmlW_getLastErrorText(HCkHtmlToXmlW cHandle, HCkString retval); const wchar_t *CkHtmlToXmlW_lastErrorText(HCkHtmlToXmlW cHandle);` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `void CkHtmlToXmlW_getLastErrorXml(HCkHtmlToXmlW cHandle, HCkString retval); const wchar_t *CkHtmlToXmlW_lastErrorXml(HCkHtmlToXmlW cHandle);` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `BOOL CkHtmlToXmlW_getLastMethodSuccess(HCkHtmlToXmlW cHandle); void CkHtmlToXmlW_putLastMethodSuccess(HCkHtmlToXmlW cHandle, BOOL newVal);` | read/write | Indicates the success or failure of the most recent method call: `TRUE` means success, `FALSE` means failure. |
| `VerboseLogging` | `BOOL CkHtmlToXmlW_getVerboseLogging(HCkHtmlToXmlW cHandle); void CkHtmlToXmlW_putVerboseLogging(HCkHtmlToXmlW cHandle, BOOL newVal);` | read/write | If set to `TRUE`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `void CkHtmlToXmlW_getVersion(HCkHtmlToXmlW cHandle, HCkString retval); const wchar_t *CkHtmlToXmlW_version(HCkHtmlToXmlW cHandle);` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `DropCustomTags` | property, read/write | `BOOL CkHtmlToXmlW_getDropCustomTags(HCkHtmlToXmlW cHandle); void CkHtmlToXmlW_putDropCustomTags(HCkHtmlToXmlW cHandle, BOOL newVal);` |
| `Html` | property, read/write | `void CkHtmlToXmlW_getHtml(HCkHtmlToXmlW cHandle, HCkString retval); void CkHtmlToXmlW_putHtml(HCkHtmlToXmlW cHandle, const wchar_t *newVal); const wchar_t *CkHtmlToXmlW_html(HCkHtmlToXmlW cHandle);` |
| `Nbsp` | property, read/write | `int CkHtmlToXmlW_getNbsp(HCkHtmlToXmlW cHandle); void CkHtmlToXmlW_putNbsp(HCkHtmlToXmlW cHandle, int newVal);` |
| `XmlCharset` | property, read/write | `void CkHtmlToXmlW_getXmlCharset(HCkHtmlToXmlW cHandle, HCkString retval); void CkHtmlToXmlW_putXmlCharset(HCkHtmlToXmlW cHandle, const wchar_t *newVal); const wchar_t *CkHtmlToXmlW_xmlCharset(HCkHtmlToXmlW cHandle);` |
| `ConvertFile` | method | `BOOL CkHtmlToXmlW_ConvertFile(HCkHtmlToXmlW cHandle, const wchar_t *inHtmlPath, const wchar_t *destXmlPath);` |
| `DropTagType` | method | `void CkHtmlToXmlW_DropTagType(HCkHtmlToXmlW cHandle, const wchar_t *tagName);` |
| `DropTextFormattingTags` | method | `void CkHtmlToXmlW_DropTextFormattingTags(HCkHtmlToXmlW cHandle);` |
| `SetHtmlBd` | method | `BOOL CkHtmlToXmlW_SetHtmlBd(HCkHtmlToXmlW cHandle, HCkBinDataW bd);` |
| `SetHtmlFromFile` | method | `BOOL CkHtmlToXmlW_SetHtmlFromFile(HCkHtmlToXmlW cHandle, const wchar_t *filename);` |
| `SetHtmlSb` | method | `BOOL CkHtmlToXmlW_SetHtmlSb(HCkHtmlToXmlW cHandle, HCkStringBuilderW sb);` |
| `ToXml` | method | `BOOL CkHtmlToXmlW_ToXml(HCkHtmlToXmlW cHandle, const wchar_t *outStr); const wchar_t *CkHtmlToXmlW_toXml(HCkHtmlToXmlW cHandle);` |
| `ToXmlSb` | method | `BOOL CkHtmlToXmlW_ToXmlSb(HCkHtmlToXmlW cHandle, HCkStringBuilderW sb);` |
| `UndropTagType` | method | `void CkHtmlToXmlW_UndropTagType(HCkHtmlToXmlW cHandle, const wchar_t *tagName);` |
| `UndropTextFormattingTags` | method | `void CkHtmlToXmlW_UndropTextFormattingTags(HCkHtmlToXmlW cHandle);` |
| `Xml` | method | `BOOL CkHtmlToXmlW_Xml(HCkHtmlToXmlW cHandle, const wchar_t *outStr); const wchar_t *CkHtmlToXmlW_xml(HCkHtmlToXmlW cHandle);` |

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 · wc · HtmlToXml · DropCustomTags · property · read/write`

```c
BOOL CkHtmlToXmlW_getDropCustomTags(HCkHtmlToXmlW cHandle);
void CkHtmlToXmlW_putDropCustomTags(HCkHtmlToXmlW cHandle, BOOL newVal);
```

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.

### HtmlToXml.Html

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

```c
void CkHtmlToXmlW_getHtml(HCkHtmlToXmlW cHandle, HCkString retval);
void CkHtmlToXmlW_putHtml(HCkHtmlToXmlW cHandle, const wchar_t *newVal);
const wchar_t *CkHtmlToXmlW_html(HCkHtmlToXmlW cHandle);
```

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 · wc · HtmlToXml · Nbsp · property · read/write`

```c
int CkHtmlToXmlW_getNbsp(HCkHtmlToXmlW cHandle);
void CkHtmlToXmlW_putNbsp(HCkHtmlToXmlW cHandle, int newVal);
```

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 · wc · HtmlToXml · XmlCharset · property · read/write`

```c
void CkHtmlToXmlW_getXmlCharset(HCkHtmlToXmlW cHandle, HCkString retval);
void CkHtmlToXmlW_putXmlCharset(HCkHtmlToXmlW cHandle, const wchar_t *newVal);
const wchar_t *CkHtmlToXmlW_xmlCharset(HCkHtmlToXmlW cHandle);
```

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 · wc · HtmlToXml · ConvertFile · method`

```c
BOOL CkHtmlToXmlW_ConvertFile(HCkHtmlToXmlW cHandle, const wchar_t *inHtmlPath, const wchar_t *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 `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.

### HtmlToXml.DropTagType

`Chilkat 11.7.0 · wc · HtmlToXml · DropTagType · method`

```c
void CkHtmlToXmlW_DropTagType(HCkHtmlToXmlW cHandle, const wchar_t *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 · wc · HtmlToXml · DropTextFormattingTags · method`

```c
void CkHtmlToXmlW_DropTextFormattingTags(HCkHtmlToXmlW cHandle);
```

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 · wc · HtmlToXml · SetHtmlBd · method · since 9.5.0.77`

```c
BOOL CkHtmlToXmlW_SetHtmlBd(HCkHtmlToXmlW cHandle, HCkBinDataW 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 `TRUE` on success and `FALSE` on failure.

Returns TRUE for success, FALSE for failure.

### HtmlToXml.SetHtmlFromFile

`Chilkat 11.7.0 · wc · HtmlToXml · SetHtmlFromFile · method`

```c
BOOL CkHtmlToXmlW_SetHtmlFromFile(HCkHtmlToXmlW cHandle, const wchar_t *filename);
```

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.

### HtmlToXml.SetHtmlSb

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

```c
BOOL CkHtmlToXmlW_SetHtmlSb(HCkHtmlToXmlW cHandle, HCkStringBuilderW 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 `TRUE` on success and `FALSE` on failure.

Returns TRUE for success, FALSE for failure.

### HtmlToXml.ToXml

`Chilkat 11.7.0 · wc · HtmlToXml · ToXml · method`

```c
BOOL CkHtmlToXmlW_ToXml(HCkHtmlToXmlW cHandle, const wchar_t *outStr);
const wchar_t *CkHtmlToXmlW_toXml(HCkHtmlToXmlW cHandle);
```

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.

### HtmlToXml.ToXmlSb

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

```c
BOOL CkHtmlToXmlW_ToXmlSb(HCkHtmlToXmlW cHandle, HCkStringBuilderW sb);
```

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.

### HtmlToXml.UndropTagType

`Chilkat 11.7.0 · wc · HtmlToXml · UndropTagType · method`

```c
void CkHtmlToXmlW_UndropTagType(HCkHtmlToXmlW cHandle, const wchar_t *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 · wc · HtmlToXml · UndropTextFormattingTags · method`

```c
void CkHtmlToXmlW_UndropTextFormattingTags(HCkHtmlToXmlW cHandle);
```

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.

### HtmlToXml.Xml

`Chilkat 11.7.0 · wc · HtmlToXml · Xml · method`

```c
BOOL CkHtmlToXmlW_Xml(HCkHtmlToXmlW cHandle, const wchar_t *outStr);
const wchar_t *CkHtmlToXmlW_xml(HCkHtmlToXmlW cHandle);
```

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.

## Deprecated members — do not use in new code

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

## Related classes

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

