Unquoted Attribute Values in XML
In XML, every attribute value must be enclosed in either double quotes or single quotes. Unlike HTML, which sometimes allows unquoted attribute values for simple strings, XML enforces quoting strictly. An unquoted attribute value makes the document not well-formed.
Why It Matters
The XML parser stops at the unquoted attribute and rejects the entire document. This is especially common when developers familiar with HTML write XML and forget that XML has stricter rules for attribute values.
Common Causes
- Carrying over HTML habits, where simple attribute values can be left unquoted, into XML, which always requires quotes.
- Hand-writing config or data files quickly and omitting quotes around numeric or single-word values like id=101.
- Generating XML by string concatenation and forgetting to wrap interpolated values in quotes.
Code Examples
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product id=101 category=electronics>
<name lang=en>Laptop</name>
<price currency=USD>999</price>
</product>
</products><?xml version="1.0" encoding="UTF-8"?>
<products>
<product id="101" category="electronics">
<name lang="en">Laptop</name>
<price currency="USD">999</price>
</product>
</products>How to Fix
- 1Wrap every attribute value in double quotes: id="101" instead of id=101.
- 2You can also use single quotes: id='101'. Both are valid in XML.
- 3If the attribute value contains double quotes, wrap it in single quotes or use " entity.
- 4Run your XML through a validator to catch all unquoted attributes at once.
Frequently Asked Questions
Can I use single quotes for XML attributes?
Do numeric attribute values need quotes too?
What if my attribute value contains a quote character?
Check Your XML Now
Our XML validator detects this error automatically and shows the exact line and column.
Open XML ValidatorCloudways · Managed Cloud Hosting
Fix this XML error, then deploy on Cloudways managed cloud (AWS, GCP, DigitalOcean).
Free 3-day trial · 30% off 3 months + free site migration with code MIGRATE303
Related XML Errors
Unescaped Special Characters in XML
Characters like &, <, and > must be escaped in XML text content. Learn how to fix unescaped character errors using entities or a CDATA block the right way.
Mismatched Tags in XML
XML tag names are case-sensitive. Learn how to fix mismatched opening and closing tags, spot nesting mistakes, and make your XML well-formed once more.
Invalid or Missing XML Declaration
Learn how to write a correct XML declaration and fix common mistakes like wrong attribute order, missing encoding, or stray whitespace before the prolog.