Skip to main content
XMLDir

Search 309 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

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 &lt;.
  • 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.

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.