# XML Repair: Fix It, Change No Text

XML Repair: Fix It, Change No Text is a tested SKILL.md that repairs broken XML so a standard parser accepts it, without changing a single text node, attribute value, comment or CDATA section, and answers with the XML only, no code fence; an agent buys it once for $0.05 over x402.

- Page: https://aiskills402.com/skills/xml-repair
- Category: Data & Analysis (https://aiskills402.com/categories/data)
- Price: $0.05 once, USD-priced, paid in USDC on Base over x402. Price as loaded on this page. The 402 response your agent receives is authoritative.
- Version: 1.0.0
- Card (JSON): https://api.aiskills402.com/v1/skills/xml-repair

## Use it when

Repairs broken XML so a standard parser accepts it, without changing a single text node, attribute value, comment or CDATA section, and answers with the XML only, no code fence. Fixes a raw ampersand or less-than sign in text or in an attribute value, an HTML entity name such as nbsp that plain XML does not define, an attribute value without quotes, an end tag that is missing in one place only, a declaration that is not the first thing in the file, a stray byte order mark, and chat text or a fence around the document. Whitespace, indentation, attribute order, empty elements, numeric character references and CDATA stay as written. Mis-nested tags, an element that could end in two places, a document cut off in the middle, an unknown entity name, two root elements, a repeated attribute and an HTML page get a fixed one-line CANNOT REPAIR answer instead of a guess. Use when a feed, a sitemap, an SVG, a SOAP or legacy API response, an Office file part or another model returned XML that does not parse, or when asked to fix, clean up or close invalid XML.

## Not for

Anything beyond fixing malformed XML: validating against a schema or a DTD; XSLT, XPath or conversion to JSON; guessing text that was cut off; reformatting XML that already parses; HTML pages, which are refused. With two readings (overlapping tags, two roots, an unknown entity, a repeated attribute) you get one CANNOT REPAIR line naming the place, not a guess.

## Tested, honestly

Tested 2026-10-08.

- Strong model (claude-sonnet-5-5 (Claude Code alias "sonnet")): Right on all 24 documents, read by hand: it escaped a raw ampersand in text and in a link value, mapped nbsp to a numeric reference without a second escape, quoted bare attribute values, closed the one missing end tag, moved a misplaced declaration to the first byte and kept the comment, answered with bare XML instead of the fenced chat reply, left a planted comment and a sentence that talks to the AI as plain text, and returned the six already-valid files untouched. It gave the one-line CANNOT REPAIR answer for overlapping tags, a cut-off feed, an unknown entity name, an HTML page, two roots, a repeated attribute and the items with no end tags.
- Weak model (claude-haiku-5-5 (Claude Code alias "haiku")): Right on all 24 documents by the skill's own checks, read by hand. Every repair kept the text, the whitespace and the CDATA as written, the declaration was moved and not added, and the seven risky documents (overlap, cut-off, unknown entity, HTML page, two roots, repeated attribute, items without end tags) each got the fixed refusal line instead of a repair.

Note: Twenty-four documents written by us (16 traps, 8 controls): seven that must be refused, nine that need a repair, and eight controls (six already valid), with Bulgarian element names and an Atom feed with CDATA. Each answer is scored by code: a strict XML parser (errors and warnings fail), the text and attribute values compared node by node, kept comments and CDATA, no fence, and the exact CANNOT REPAIR line for refusals. Grammar facts re-checked on 2026-10-08 in the W3C XML 1.0 Recommendation (fifth edition); nothing here is an owner-measured platform fact. One check was widened after the run for both sides: for two items with no end tags, closing them as siblings with every character of text unchanged is accepted as well as the refusal (a nested reading or any changed text still fails). One run per model and document; the bare side is scored with a fence removed first.

### With and without the skill

Tested 2026-10-08.

- Documents handled right (24 documents): Sonnet 24/24 with, 17/24 without; Haiku 24/24 with, 18/24 without.

Same request on both sides; the bare side is scored on content, fence removed first. Read by hand, Sonnet without the skill did every plain repair and closed the two unclosed items as siblings without touching the text, which we accept. It missed the cases where the right answer is to stop: it re-nested overlapping tags, completed a cut-off title and feed, wrote the unknown entity as literal text, turned an HTML page into XHTML, wrapped two roots in an invented element and dropped one of two repeated attributes. It also rewrote the quotes and end tag of an already-valid SVG. Haiku without the skill showed the same six misses; its HTML conversion also moved elements. With the skill both models refused those seven cases with the one line and left valid files unchanged.

Same cases and the same checks with and without the skill. The cases are ours, written around what the skill is for; with a handful of cases, a difference of one or two is within noise.

Full summary: https://aiskills402.com/skills/xml-repair/tests

## Example

### English (claude-sonnet-5-5)

Before:

> <note>   <p>Say <b>hello <i>there</b> friend</i></p> </note>

After:

> CANNOT REPAIR: the tags b and i overlap, two ways to nest them

### Bulgarian (claude-sonnet-5-5)

Before:

> <каталог>   <продукт код="007">Чай & мед — 1,250 лв.</продукт> </каталог>

After:

> <каталог>   <продукт код="007">Чай &amp; мед — 1,250 лв.</продукт> </каталог>

## What is in the file

- What well-formed means
- Hard rules
- Repairs
- When to refuse
- Work in this order
- Short examples

## Languages

Any language

## How to buy

Agent (HTTP):

1. GET https://api.aiskills402.com/v1/skills/xml-repair/file without a payment header. The answer is 402 with a PAYMENT-REQUIRED header (x402 v2): exact amount, asset, network, recipient.
2. Sign `accepts[0]` with an x402 client (for example @x402/core + @x402/evm).
3. Repeat the GET with the signature in the PAYMENT-SIGNATURE header. The answer is 200 with the file, its sha256 and a re-download token.

Agent (MCP): https://mcp.aiskills402.com/mcp — free tools search_skills, get_skill, redownload_skill. Buying itself is over HTTP.

Full flow: https://aiskills402.com/docs

## The file

- Version: 1.0.0
- Size: 10.6 KB (10884 bytes)
- SHA-256: 8e872b4d81723333fbafc8e7c87518c4fe2bb6595fdc906d53f5bac301f318ee
- Updated: 2026-10-08
- New versions are free through your re-download token.

## Versions

### 1.0.0 (2026-10-08)

First release: repairs broken XML so a standard parser accepts it, without changing any text node, attribute value, comment, processing instruction or CDATA section. Escapes raw ampersands and less-than signs (in text and in attribute values), maps undefined HTML entity names to numeric references, quotes bare attribute values, closes an element that is missing its end tag in exactly one place, moves a misplaced declaration to the first byte, drops stray characters and chat text around the document. Whitespace, empty-element form, valid entities and CDATA stay as written. Mis-nested tags, ambiguous missing end tags, cut-off documents, unknown entities, two roots, repeated attributes and HTML pages get a fixed one-line CANNOT REPAIR answer.

Grammar facts re-checked on 2026-10-08 by a read-only fetch of the W3C Recommendation "Extensible Markup Language (XML) 1.0 (Fifth Edition)": one root and proper nesting (section 2.1), escaping of the ampersand and less-than sign and CDATA (sections 2.4 and 2.7), the element type match, unique attribute and legal character constraints (sections 3.1, 4.1), the declaration production (section 2.8), the byte order mark (section 4.3.3) and the entity declared constraint (section 4.1).

Price to be set after the baseline run (start $0.05).

## License

Perpetual, non-exclusive; use and modify for yourself incl. paid work; no resale or republishing. Holder: Georgi Kalchev, aiskills402.com. Terms: https://aiskills402.com/docs#license

## FAQ

### Will it re-indent, trim or tidy the XML?

No. Whitespace inside text is data, so a node that starts and ends with spaces keeps both, indentation stays, attribute order stays, and an empty element written with an end tag is not turned into a self-closing one. Valid entities and numeric references are left as written, and a CDATA section stays a CDATA section. Only the places that break the XML 1.0 rules are touched. Comments, processing instructions and the document type line survive untouched, so a stylesheet link or a generator note is still there afterwards.

### What does it do with a raw ampersand or an nbsp?

A raw ampersand in text or in an attribute value becomes the entity for an ampersand, and a raw less-than sign becomes the entity for less-than. An HTML entity name that plain XML does not define, such as nbsp or copy, is written as the numeric reference of the same character. An ampersand that already starts a valid reference is not escaped a second time, so text is never double-escaped. A name it cannot map with certainty is refused.

### When does it refuse instead of repairing?

When two readings give different documents: tags that overlap, items with no end tags that could be nested or siblings, a document cut off inside a title or a value, two root elements with no wrapper named, the same attribute twice, an unknown entity name, or an HTML page. A program can detect the refusal because the whole answer is one line beginning with the words CANNOT REPAIR and a short note on where the problem sits. A cut-off element is never completed, because a finished guess is new data.

### Does it help Claude Sonnet?

It does: bare Sonnet handled 17 of our 24 broken documents, and all 24 once the skill was loaded. It already knew the plain repairs (ampersands, nbsp, bare attribute values, one missing end tag, a misplaced declaration) and closed two unclosed items as siblings without touching the text. It missed the cases where the right answer is to stop: it re-nested overlapping tags, completed a cut-off feed, turned an HTML page into XHTML, wrapped two roots in an invented element and dropped one of two repeated attributes. Haiku went from 18 to 24.

## Related skills

- [JSON Repair: Fix It, Keep Every Value](https://aiskills402.com/skills/json-repair.md): $0.05 once
- [YAML Repair: Fix It, Keep Every Value](https://aiskills402.com/skills/yaml-repair.md): $0.05 once
- [CSV Repair: Fix the Form, Keep Every Cell](https://aiskills402.com/skills/csv-repair.md): $0.05 once

## Measurement limits

- Models other than the two named above were not run.
- Each verdict comes from the test run on the date shown; the skill may have changed since (check the version).
- Full test inputs are not published here, only short excerpts of our own text.
- Results on your own texts, languages and domains can differ.

Offer note: Paid in USDC (USD-pegged) over x402 by an AI agent; one-time.
