Document structure
Attribute
A name–value pair on an element's start tag, whose value is always a quoted string.
Attributes are unordered, unique per element, and always strings. A schema can say a value must look like an integer or a date, but the document itself carries text — which is why attribute order is not a difference, and why a canonicalizer is free to sort them.
Values must be quoted, with single or double quotes, and the value cannot contain a bare < at all. Whether to model data as an attribute or a child element is one of XML's oldest arguments; the practical difference is that attributes cannot repeat, cannot nest, and cannot carry structure.
- Defined in
- XML 1.0 §3.1
- Category
- Document structure
- Also written
- name="value" pair
Shown, not asserted
All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.
Repeating an attribute on one element is a well-formedness error.
document.xml <x a="1" a="2"/>What the engine returns
Attribute a redefined (line 1)Attribute order is not information: canonicalization sorts it away.
document.xml <r z="26" a="1"/>What the engine returns
c14n <r a="1" z="26"></r>
What catches people out
- A bare < is illegal inside an attribute value even though > is fine. Escape it as <.
- Unprefixed attributes are in no namespace, even when the element declares a default namespace.
- Attribute values are normalized before anything sees them: literal tabs and newlines become spaces.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Parse errorsAttribute redefinedThe message a duplicated attribute produces.
- Parse errorsUnquoted attribute value (AttValue expected)What HTML-style valueless attributes report.
- Parse errorsAttributes construct error (unterminated quote)The failure when a value is unquoted or the quote never closes.
- Schema errorsThe attribute is required but missingThe validation error for an attribute a schema demands.
Related terms
- ElementThe unit of structure in XML: a start tag, its content, and a matching end tag — or a single self-closing tag when there is no content.
- Attribute-value normalizationThe parser's rewriting of attribute values before anything sees them: literal tabs, newlines and carriage returns become spaces.
- Default namespaceThe namespace declared by a bare xmlns="…", which applies to unprefixed element names on that element and its descendants.
- Predefined entityOne of the five entities every XML parser knows without a declaration: &, <, >, ' and ".
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.