Skip to main content

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

XML format

OpenStreetMap XML

The editing format behind OpenStreetMap: nodes, ways and relations carrying free-form tags rather than a fixed schema.

OSM XML is what the OpenStreetMap API serves and what editors exchange. It has exactly three element types — <node> for a point, <way> for an ordered list of nodes, and <relation> for a grouping — and all meaning beyond geometry comes from <tag k= v=> pairs whose keys are conventions agreed by the community rather than a schema.

That is the format's strength and the thing that surprises people building on it. There is no schema to validate against for tagging: highway=residential is meaningful because a wiki page and a rendering stack agree it is, not because any file says so. The same feature may be tagged three ways in three countries, all of them correct.

Constraints that bite

  • Geometry is by reference: a way carries <nd ref> pointers, not coordinates. Resolving a way needs its nodes, which may not be in the same file.
  • Tag keys are conventions, not a schema. Nothing rejects a misspelled key — it simply renders nowhere.
  • Negative IDs mean new objects not yet uploaded; positive ones are server-assigned. Mixing the two conventions corrupts a changeset.
  • The version attribute is used for optimistic locking on upload; sending a stale version is how an edit conflict is reported.
  • Full planet extracts are served as PBF rather than XML for a reason — XML for a large region is tens of gigabytes.
Root element
<osm>
Media type
application/xml
Extensions
.osm, .xml
Namespaces
None — unqualified elements
XMLDir label

Specification: OSM XML format

A minimal valid document

Every example on this site is checked against the same parser the workspace uses, so what you see below is known to be well-formed.

osm.xml
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="example">
  <node id="1" lat="51.5074" lon="-0.1278" version="3"/>
  <node id="2" lat="51.5080" lon="-0.1270" version="1"/>
  <way id="10" version="2">
    <nd ref="1"/>
    <nd ref="2"/>
    <tag k="highway" v="residential"/>
    <tag k="name" v="Example Street"/>
    <tag k="maxspeed" v="20 mph"/>
  </way>
</osm>

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.