Format Code Now
/
ConvertHTML to XML Next: JSON to HTML ›

HTML to XML Converter

CV-102

Paste HTML, including loose markup, and get well-formed XML with every tag closed, every attribute quoted and text escaped.

Runs in your browser. Nothing is uploaded.

HTML

XML

How to use it

  1. Paste your HTML.
  2. Pick a layout: an indent size, or Keep original whitespace.
  3. Tick or untick the XML declaration.
  4. Press HTML to XML, then copy or download.

What gets fixed

HTML allows things XML does not. The tool closes void tags (<br> becomes <br/>), closes tags that HTML lets you leave open, such as li and p, quotes unquoted attributes, and writes an attribute with no value as its own name, so checked becomes checked="checked". Tag and attribute names are lowercased, duplicate attributes keep the first, and names XML does not allow have the bad characters replaced with an underscore.

What is dropped or changed

Comments, the doctype and processing instructions are not carried over. Character references like &nbsp; become the real character, and &, < and > are escaped again. If the HTML has several top-level elements they are wrapped in a root element, because XML allows only one. The indented layouts trim and collapse spaces between tags, which can change spacing around inline tags such as b and a. Keep original whitespace avoids that. Control characters XML cannot hold are an error.

Error messages and what to do

MessageWhat it meansFix
No HTML elements found to convertThe input has no tags.Paste markup that has at least one element.
The HTML contains a control character that XML 1.0 cannot holdA character such as a null byte cannot appear in XML.Remove the control character from the input.

Questions people ask

How do I convert HTML to XML?

Paste the HTML and press HTML to XML. The tool closes every tag, quotes every attribute and escapes the text, then adds an XML declaration. Copy the result or download it as a .xml file.

Is the result valid XHTML?

It is well-formed XML, and the elements keep their HTML names. It does not add the XHTML namespace or check the document against the XHTML rules, so add the namespace yourself if a consumer requires it.

Why did my wrapper element appear?

XML needs exactly one root element. When your HTML has more than one top-level element or loose text at the top, the tool wraps everything in a root element so the output stays valid.

What happens to attributes without values?

They get their own name as the value, so disabled becomes disabled="disabled". This is the usual XHTML form. A duplicate attribute keeps its first value, as HTML parsers do.

Will it keep my comments?

No. Comments, the doctype and processing instructions are all dropped during conversion. If you need comments in the XML output, add them by hand after the conversion has finished.

About this tool

Reads the HTML with a tolerant parser, closes open tags the way browsers do, and writes XML. Tag and attribute names are lowercased. Void tags such as <br> and <input> become <br/> and <input/>, an attribute with no value gets its own name as the value (checked="checked"), and duplicate attributes keep the first. Names that XML does not allow have those characters replaced with _. Character references such as &nbsp; are decoded to the real character, then &, < and > are escaped. Comments, the doctype and processing instructions are dropped. If the HTML has several top-level pieces they are wrapped in <root>. The Layout option adds indentation and collapses spaces between tags, which can change whitespace around inline tags; Keep original whitespace does not. Control characters XML 1.0 cannot hold are an error.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.