HTML to XML Converter

Paste loose HTML. Get well-formed XML back.

Input

Output

Paste your HTML on the left and press Convert.

Or drop a file on this box, , or .

What this tool does

If you have ever had to feed a copy-pasted HTML snippet into an XSLT pipeline or a strict XML parser, you already know the pain. Browsers are famously forgiving: the HTML parser in the WHATWG spec will silently close your <li> tags, accept unquoted attributes, and shrug at a missing </p>. An XML parser will not. Feed it the same markup and you get a parse error on line 3. This tool takes real-world HTML, the kind you actually paste from a CMS or a legacy template, and turns it into XML that a standards-compliant parser will accept on the first try.

It is more than just closing tags. The converter handles the full set of things that make HTML loose and XML strict: void elements like <br>, <img>, and <hr> get self-closed as <br/>; boolean attributes like checked and disabled are expanded to checked="checked"; unquoted attribute values get wrapped in double quotes; tag names are lowercased for consistency; and the handful of named HTML entities that XML does not know about (&nbsp;, &mdash;, &pound;, &times;, and so on) get converted to numeric entities like &#160; that every XML parser understands.

Comments come through intact. CDATA sections inside <script> and <style> are preserved. The output is pretty-printed so you can actually read it, and it will pass W3C validation as an XML document or slot straight into an XHTML 1.0 workflow. If what you really want is XHTML Strict, this gets you 95% of the way there: you can add the doctype and namespace at the top yourself.

How to use it

Paste the markup, press Convert, copy the result. A single <p> and a full page template are handled the same way.

1

Paste your HTML (or try the sample)

Paste HTML into the left editor without tidying it. Unclosed <li> and <p> tags, attributes with no value, unquoted attribute values and bare <br> or <img> tags are exactly what the converter is for. Load Sample loads an order card that breaks all of those rules at once, plus a couple of named entities.

You do not need to hand-fix anything. The whole point of this tool is that it does the cleanup for you. Paste it exactly the way it came out of your CMS, Word doc, or legacy template.

2

Hit Convert

Press the green Convert button. The markup is sent to the backend, which closes every open tag, quotes every attribute, adds the slash to void elements and turns each entity XML does not define into its numeric form. Expect a brief "Converting..." overlay while that happens.

3

Copy the XML

The read-only right pane shows indented markup that a strict XML parser will load. Copy it into an XSLT input, a DOM test fixture, an EPUB chapter or any other pipeline that rejects tag soup.

When this actually comes in handy

Feeding HTML into XSLT or an XML pipeline

You have an XSLT stylesheet that turns content into a PDF, a feed, or another format, but your input is HTML from a CMS, not XML. Convert first, transform second.

XHTML-strict validation

Legacy intranet that still demands XHTML 1.0 Strict? Paste the sloppy HTML your editor produced, copy out the XML, drop a doctype on top, and you are done.

Converting blog markup for EPUB / e-readers

EPUB is XHTML under the hood and will flat-out reject a missing </p>. Clean up a chapter’s worth of blog HTML in one paste before packaging.

Cleanup for archival systems

Feeding old HTML into an XML-based archive (DSpace, Fedora Commons, anything JATS-flavoured)? Strict schemas do not care that the browser rendered it fine: convert it first.

Common questions

What actually makes HTML "loose" and XML "strict"?

There are three main differences. Void elements such as <br>, <meta> and <img> never get a closing tag in HTML, while XML needs <br/>. HTML also allows <li> and <p> to stay open because the HTML parsing algorithm closes them for you. And HTML accepts class=card without quotes and disabled with no value at all. An XML parser stops with an error on any of the three.

What happens to boolean attributes like `checked` and `disabled`?

They get expanded into the XHTML form. <input type=checkbox checked disabled> becomes <input type="checkbox" checked="checked" disabled="disabled"/>. Every attribute ends up with a name AND a quoted value, which is what XML requires: there is no such thing as an attribute without a value in XML.

How are HTML entities like `&nbsp;` and `&mdash;` handled?

XML only knows five named entities out of the box: &amp;, &lt;, &gt;, &quot;, &apos;. Everything else (&nbsp;, &mdash;, &pound;, &copy;) is converted to its numeric form (&#160;, &#8212;, &#163;, &#169;) so any XML parser will accept them without a DTD.

Do comments survive the round trip?

Yes. <!-- flagged for review --> goes in, the same thing comes out. Comments are valid in both HTML and XML with the same syntax, so they pass through untouched: handy if you use them for editorial notes or build-time markers.

Does it lowercase tag and attribute names?

Yes, by default. <DIV Class="Foo"> becomes <div class="Foo">. Tag and attribute names are lowercased to match the XHTML 1.0 convention. Attribute VALUES are left alone: we do not touch the content you put inside quotes, because that is your data.

When is this not enough: what cases does the tool NOT handle?

Arbitrary <script> content is preserved as text, but the tool does not try to rewrite JavaScript to be XML-safe. If your JS uses bare < or & characters you will need to wrap it in <![CDATA[...]]> yourself (we preserve existing CDATA). Document fragments are fine. The output starts with an <?xml version="1.0" encoding="UTF-8"?> declaration, and any HTML doctype is dropped because it is not valid in an XML document body.

Other tools you may need

Once the HTML is well-formed XML, these pages help you validate it, query it, or turn it into JSON: