Data and structured data
Why will this XML not parse?
Tools to use
An imported XML file fails at its last line. Adding a closing tag only moves the error elsewhere. Reduce the document to one record and trace where each element begins and ends. A parser's detection point is not necessarily the location where the mistake was introduced.
Use a fictional order in XML Formatter. Before returning a formatted document to an application, check the order ID, name and amount. Real customer data or credentials are unnecessary. Readable indentation does not establish that the order or receiving application's schema is correct.
Match names before adding tags
<order id="A-17"><name>Notebook</title><amount>1200</amount></order>The element starts as name but closes as title. Run it and confirm that formatting fails. Investigate that mismatch before changing the final order tag. Do not infer the required field name from the text Notebook: establish whether the receiving format expects name or title, then make both ends agree.
<order id="A-17"><name>Notebook</name><amount>1200</amount></order>After the repair, name and amount should be siblings inside order. The formatter does not decide the meaning of a broken field. Deleting an unfamiliar element might remove the error by deleting required information. Change one thing at a time so you can explain which edit solved which problem.
Equal tag counts do not prove correct nesting
<order><item><name>Notebook</item></name></order>There is one opening and one closing tag for every name, yet item closes before the inner name element. Close the innermost element first: name, then item, then order. Counting tags cannot detect this crossing; you must follow the hierarchy.
Compare a failing record with a known-good one. If one item works but two do not, inspect the boundaries of the repeated section. Keep the outer root element when reducing a document, otherwise your reduction may create a different error from the original one.
Keep text characters separate from markup
<order><name>Pen & Paper</name><note>count < 10</note></order>Represent the ampersand in Pen & Paper as & and the less-than sign in count < 10 as <. You are changing the XML representation, not renaming the product. Distinguish characters in the decoded value from the spelling used to carry them in XML source.
Replacing every & in an already encoded document can turn & into &amp;, delivering the literal text &. Keep raw-text encoding separate from processing completed XML. Seeing character references in formatted source is not necessarily an error; this is not an HTML rendering of the field value.
Attribute quotes define value boundaries
<item code="A-17" note="Use "small" size"><name>Notebook</name></item>The note attribute uses double quotes as delimiters, so an internal double quote is written as ". Ending the delimiter too early can make the remaining text look like another attribute. Test fictional values with a space, ampersand and quotation mark separately; a one-word value does not exercise those boundaries.
This tool checks syntax within its parser's supported behavior, not every XML conformance condition. Do not assume HTML-style valueless attributes are valid XML. Acceptance by this formatter does not guarantee acceptance by the receiver; check its documented input format and test in that environment.
An empty amount can still have valid tags
Replace 1200 with an empty value, or with twelve. Matching tags may still format successfully. Syntax alone cannot establish whether an amount is mandatory, numeric or expressed in a particular currency. Separate structural checking from business-field validation so the result has a clear meaning.
The screen does not validate orders against an XSD or submit them to a receiver. DTD and entity declarations are rejected rather than loaded. Removing a DOCTYPE merely to get past the error may change meaning; investigate its dependencies in an appropriate safe validation environment.
Hand over both values and structure
Describe the matching tags and escaped characters, not just that formatting succeeded. Check A-17, Notebook and 1200, then repeat with an ampersand in the name. Mixed-content documents where whitespace matters, or signed XML, require more than this check before reformatted output is reused.
Keep the original minimal failing example alongside the repaired one. Separate cases for mismatched names, crossed nesting and quotes in attributes make future regressions easier to diagnose. A fictional reproducer communicates the failure without sharing a large production document.