Mismatched Closing Tag | The closing tag does not match the opening tag. In XML, every opening tag must have a corresponding closing tag with the exact same name. Common causes:- Typos in tag names
- Copy-pasting errors
- Case sensitivity mismatch (XML is case-sensitive)
How to fix:- Check the spelling of both opening and closing tags
- Ensure case matches exactly (e.g., <User> and </user> is invalid)
- Use an editor with tag matching to highlight pairs
| <user>
<name>John</name>
</users>
<user>
<name>John</name>
</user>
|
Missing Closing Tag | An opening tag is present but the closing tag is missing. Common causes:- Forgetting to close a tag
- Nesting errors where a parent tag is closed before its children
- Self-closing tag syntax errors
How to fix:- Locate the unclosed element
- Add the closing tag (</tagname>) at the appropriate position
- Use self-closing syntax (<tag />) for empty elements
| <note>
<to>Tove</to>
<from>Jani
<body>Don't forget me this weekend!</body>
</note>
<note>
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me this weekend!</body>
</note>
|
Unquoted Attribute Values | Attribute values must always be quoted in XML. Unlike HTML, XML is strict about quotes. Common causes:- HTML habits (HTML often allows unquoted attributes)
- Lazy typing
- Generating XML via partial string concatenation
How to fix:- Wrap all attribute values in double quotes (") or single quotes (')
- Example: page="1" instead of page=1
| <message date=2023-10-25>
Hello
</message>
<message date="2023-10-25">
Hello
</message>
|
Improper Nesting | Tags are not nested correctly. A tag opened inside another tag must be closed before the outer tag is closed. Common causes:- Confusing the order of closing tags
- Editing large blocks of XML
How to fix:- Follow the LIFO (Last In, First Out) rule for tags
- Close the specific inner element before closing the outer wrapper
| <b><i>Bold and Italic</b></i>
<b><i>Bold and Italic</i></b>
|
Multiple Root Elements | An XML document must have exactly one root element that contains all other elements. Common causes:- Concatenating two XML files
- Forgetting a wrapper element
- Fragments of XML data
How to fix:- Wrap your elements in a single parent element (e.g., <root> or <data>)
- Ensure the declaration <?xml ...?> is at the very top, followed by one root tag
| <user>John</user>
<user>Jane</user>
<users>
<user>John</user>
<user>Jane</user>
</users>
|
Unescaped Special Characters | Using special characters like <, >, &, ", or ' directly in text or attributes without escaping them. Common causes:- Pasting raw text content
- URLs containing ampersands (&)
- Mathematical formulas (< or >)
How to fix:- Replace < with <
- Replace > with >
- Replace & with &
- Replace " with "
- Replace ' with '
- Or wrap content in a CDATA section: <![CDATA[5 < 10]]>
| <equation>5 < 10 & 10 > 5</equation>
<equation>5 < 10 & 10 > 5</equation>
|