# Fix an XML opening and ending tag mismatch

Source: https://xsdhub.com/learn/xml-tag-mismatch

Find mismatched XML tags with a tested broken example, corrected XML and an in-browser validator. Check nesting, spelling and case.

## The quick fix

Match each closing tag to the most recent opening tag that has not yet been closed. In our example, itemz must be item. XML names are case-sensitive: Item and item are different names. Fix the source XML rather than changing the schema.

## Read the first mismatch

XSDHub reports the opening name and the unexpected closing name. Inspect both lines and the enclosing element. A missing close tag earlier in the document can cause a mismatch later, so the reported line is a starting point rather than proof that only that line is wrong.

## Check nesting as well as spelling

Closing names may all exist and still be in the wrong order. <a><b></a></b> is malformed; close b before a. An empty element can use <b/> or the pair <b></b>. Do not remove content simply to make a parser accept the file.

## Prevent the error at its source

Generate XML with an XML serializer rather than assembling strings. If this came from an export, repair the template or generator and regenerate the document. Check a small failing sample before processing a batch.

## What a successful check means

A syntax pass confirms well-formed XML. It does not verify element order, required fields or data types against an XSD. After repairing syntax, run schema validation if your receiver provides a schema.

## Primary references

- [W3C XML: start-tags, end-tags and empty-element tags](https://www.w3.org/TR/xml/#sec-starttags)
