Xerobit

XML to HTML Converter

Paste your XML to convert it into colorized HTML markup that displays the raw structure on any web page. The converter uses a hand-written tokenizer to verify well-formedness, reporting the exact line and column of the first error. It runs entirely in your browser so nothing is uploaded.

HTML output

How to use the xml to html converter

  1. Paste or type your XML into the input area.
  2. The tool immediately tokenizes the input and checks for well-formedness errors.
  3. If an error is found, the message shows the exact line and column where parsing stopped.
  4. Copy the generated HTML from the output area and paste it into your web page or template.

How the tokenizer works

The xml to html conversion relies on a hand-written state-machine tokenizer rather than the browser's built-in DOMParser. It reads the input character by character, tracking line and column numbers. When it encounters a left angle bracket it determines whether the next construct is an element, a comment, a CDATA section, or a processing instruction. Text nodes are collected until the next bracket.

Each recognized token is wrapped in an HTML <span> with a specific CSS class: xt for tag names, xa for attribute names, xv for attribute values, xc for comments, xd for CDATA sections, and xp for processing instructions. Angle brackets, slashes, and equals signs are escaped and placed outside spans so you can style punctuation independently.

Well-formedness rules enforced

To produce reliable output the tokenizer enforces several XML well-formedness constraints. Every start tag must have a matching end tag, and tags must nest correctly. Attribute names cannot repeat within a single element. Entity references are limited to the five predefined ones (&amp;, &lt;, &gt;, &quot;, &apos;) plus decimal and hexadecimal numeric character references like &#65; or &#x42;.

External entities, DOCTYPE declarations, and DTD subsets are not supported. If your document uses these features the tokenizer will report an error at the point where the unsupported construct begins. For documents that need those features, consider pre-processing them before using this xml to html converter.

Styling the output

The generated HTML contains no inline styles or scripts. You provide the colors through your own stylesheet. Here is a minimal example that produces a readable dark-on-light scheme:

CSS classPurposeExample color
.xtTag names#800000
.xaAttribute names#ff0000
.xvAttribute values#0000ff
.xcComments#008000
.xdCDATA sections#808000
.xpProcessing instructions#800080

Wrap the output in a <pre><code> block to preserve whitespace and indentation from the original XML.

Error reporting format

When the tokenizer encounters invalid markup it stops immediately and returns an error string in the format Error at line L, column C: description. Line and column counting starts at 1. Columns count characters, not bytes, so multi-byte Unicode characters each occupy one column position.

Common errors include mismatched closing tags, unquoted attribute values, unterminated comments, and invalid entity references. Because the parser halts at the first problem, fix that error and re-run to discover subsequent issues. This strict approach ensures the xml to html output always represents valid, well-formed markup.

Worked examples

ExampleInputResult
Simple documentXML input: <note><to>User</to><body>Hello</body></note>&lt;<span class="xt">note</span>&gt;&lt;<span class="xt">to</span>&gt;User&lt;/<span class="xt">to</span>&gt;&lt;<span class="xt">body</span>&gt;Hello&lt;/<span class="xt">body</span>&gt;&lt;/<span class="xt">note</span>&gt;
Attributes and CDATAXML input: <config version="1.0"><![CDATA[raw <data>]]></config>&lt;<span class="xt">config</span> <span class="xa">version</span>=<span class="xv">&quot;1.0&quot;</span>&gt;<span class="xd">&lt;![CDATA[raw &lt;data&gt;]]&gt;</span>&lt;/<span class="xt">config</span>&gt;
Processing instructionXML input: <?xml version="1.0"?> / <root/><span class="xp">&lt;?xml version=&quot;1.0&quot;?&gt;</span> / &lt;<span class="xt">root</span>/&gt;

FAQ

Does this tool parse my XML using the browser's DOMParser?

No. It uses a custom hand-written tokenizer that processes the input as plain text. This avoids browser-specific quirks and gives precise line and column numbers for errors.

Can I convert XML with DOCTYPE or external entities?

DOCTYPE declarations and external entities are not supported. The tokenizer will report an error if it encounters them. Remove or resolve these constructs before converting.

Is my XML data sent to a server?

No. All processing happens locally in your browser. Nothing is uploaded or transmitted.

What entity references are recognized?

The five predefined XML entities (amp, lt, gt, quot, apos) and numeric character references in decimal (A) or hexadecimal (B) form. Custom named entities are not supported.

How do I add colors to the converted output?

The output uses span elements with classes like xt, xa, xv, xc, xd, and xp. Add CSS rules targeting those classes in your stylesheet to apply colors.

Why does the converter stop at the first error?

XML requires strict well-formedness. Continuing past an error would produce unreliable output, so the tokenizer halts and reports the exact location of the first problem.