Help on XML export

I’m a newbie to OSM and wanted to use the xml data for my 3rd Year degree Computing project. I’m having trouble reading the tags (nodes) correctly and would appreciate any advice/assistance.
E.g; Is there a list of the tag definitions and the tree structure of the xml file anywhere or is there a standard xml setup for reading osm files. Or have I just used the wrong export (I think I just used the std “OpenStreetMap XML Data” selection)?

Thanks for any assistance

on the export Tab you click on “OpenStreetMap XML Data” and hit “Export”.

Then you should get a map.osm which is the xml file with all the nodes, ways and relations.

Looks like:

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="OpenStreetMap server">
  <bounds minlat="51.63868" minlon="7.38102" maxlat="51.65356" maxlon="7.41128"/>
  <node id="71105169" lat="51.6387564" lon="7.3873334" version="1" changeset="166848" user="rotwang" uid="11180" visible="true" timestamp="2007-10-14T17:15:35Z">
    <tag k="created_by" v="JOSM"/>
  <node id="71105175" lat="51.6389788" lon="7.3863693" version="1" changeset="166848" user="rotwang" uid="11180" visible="true" timestamp="2007-10-14T17:15:35Z">
    <tag k="created_by" v="JOSM"/>

But you can export only small regions. For large areas you can download files for example from


Hi Chris
Thanks for the details, but I’d already got that far and got the file.

It’s being able to read the file correctly thats the issue. I’m in Brighton and have downloaded a section of Brighton and surrounding area and have tags titled member, node, way etc, but a standard Java xml file-reader program is having problems with the tags. That’s why I asked if there was a ‘listing’ of the tags/nodes etc?

Is there something special/different between an osm file and a ‘standard’ xml file?


The OSM data format is indeed XML but the data is largely held in attributes.
Take the above snippet.

The area that the document is describing is defined in the bounds element’s attributes minlat, minlon, maxlat, maxlon.

The node element contains meta data in it’s attributes and has a child element, tag.
The tag element contains a key value pair in the attributes k and v respectively. This is the juicy stuff, like amenity:pub, and that’s the actual data you’re interested in I imagine.

Parsing the file and actually accessing the data does require that you have a little knowledge but that’s the case with any XML format. XHTML contains a title element, for example, and the browser knows to look for that so that it can display a page title.

XML may be self describing but you still have to instruct the parser which elements you want to access. :slight_smile:

That’s really useful for what I’m trying to do, which is use the nodes/attributes (and probably elements of the tag data) to plot routes in a Java program.

Is there any further info anywhere on parsers, or what data a standard parser would need (I’m especially presuming I’m going to need elements of the meta data attributes, such as the node’s “id” and also the various elements of the ‘way’ tags)?

Also, is there a full list of the tag elements anywhere?


Take a look at Osmosis.

Do you mean a list of keys and values that the k and v attributes on the tag element can take?
If so, then no. OpenStreetMap is freeform allowing anyone to use whatever keys and values they like.

However there are certain standardised forms.

Hi Alex
Sorry to follow this up after such a gap but I thought I had this sorted!!
Following on from your description of the tags and elements, I’m still have severe problems accessing the values of the tags. I’m using Java and all the examples I’m working on work for “standard” xml file and I can access and read most things, but…

In the example below (from a map of Brighton)


I can access the attributes of ie id, timestamp etc and, using ‘getChildNodes()’ I can count how many nd and tag elements there are in the example, but I cannot seem to view, access or otherwise report on the k and v values. These are obviously the most vital ones.
Have you got any advice on what I might be missing or otherwise how to access these k and v elements?

Huge Thanks

You have something like:?

  ChildNodes = ...getChildnodes();

And using ChildNodes you can determine how many nd and tag and…

But then ChildNodes should contain the data too. There should be other operations available to handle ChildNodes. Please show us the returnvalue of getChildNodes().

By the way: you can better change the subject of this topic to How to import XML or How to parse XML as that is where you have problems with. You aren’t exporting anything.

I have a method printAtt4 as below, (and fullWayLst is a NodeList of all the ‘way’ elements from my map set). This was one of my attempts to get at the tag data, all others were equally unsuccessful.

public void printAtt4()
for (int s=0; s < fullWayLst.getLength(); s++)
Node aSet = fullWayLst.item(s);
if (aSet.getNodeType() == Node.ELEMENT_NODE)
Element test = (Element)aSet.getChildNodes();
Element lev1 = (Element)test.getChildNodes();
String res = test.getAttribute(“version”);
String res1 = lev1.getAttribute(“v”);
System.out.println("Version is “+res+” and tag is "+res1);

This method returns a long set (the number of lines in my NodeList) but all in the following format
– Version is 2 and tag is (ie blank)

So, it picks up the Version meta-attribute of the way node, but cannot get at the tag data. This is working on a ‘way’ node as per my earlier example.

Does this help identify the issue?

Where does this ‘test’ object come from? What type? What does it contain?

Nothing… as far as I can see. But it has output.

Does aSet contain one complete node like posted above?

To go through your questions in order;

  • test is an Element object and is local to the method

  • The method is not designed to return anything per se, just to test that I can access the data correctly, hence only output. Element test should be the return from aSet.getChildNodes() and lev1 should be (hopefully) the return from (Element)test.getChildNodes()

  • aSet is a single way Node for each cycle through the for loop; this is looping through the NodeList fullWayLst, which contains all way Nodes from mymap set

Hope this helps

You are right. I oversaw that in the line before. Sorry.

Then it’s name is quite confusing for someone who tries to give help. Why not call it aWay ? And test is also a non descriptive name for a variable.

What is the type of Node in:
Node aWay = fullWayLst.item(s);
Did you define Node yourself?

Now if you write:
Element Tag = (Element)aWay.getChildNodes();

then I shiver because getChildNodes() will return most likely more than one ChildNode (The 's) . So why do you cast that to one? Looks not ok to me.

I would expect:
SomeType Tags = aWay.getChildNodes();

And after you need another loop. Loop through Tags to get the Tags one by one and then do something with


I wonder why you manage to extract the right “version”. I do not understand that code as as it looks you get that from a childnode from your way.