private static List<OSMWay> getWays(Document xmlDocument, List<OSMNode> nodes) {
		List<OSMWay> result = new ArrayList<OSMWay>();
		Map<String,OSMNode> nodeMap = new HashMap<String, OSMNode>();
		for(OSMNode n : nodes) {
			nodeMap.put(n.id, n);
		}
		Node osmRoot = xmlDocument.getFirstChild();
		NodeList osmXMLNodes = osmRoot.getChildNodes();
		for (int i = 1; i < osmXMLNodes.getLength(); i++) {
			Node item = osmXMLNodes.item(i);
			if (item.getNodeName().equals("way")) {
				OSMWay way = new OSMWay();
				way.id = ((Element)item).getAttribute("id");
				result.add(way);
				way.addTags(getTags(item));
				NodeList wayNodes = item.getChildNodes();
				for (int j = 1; j < wayNodes.getLength(); j++) {
					Node wayItem = wayNodes.item(j);
					if(wayItem.getNodeName().equals("nd")) {
						String ref = wayItem.getAttributes().getNamedItem("ref").getNodeValue();
						OSMNode node = nodeMap.get(ref);
						if(node != null) {
							way.nodes.add(node);
						} else {
							throw new RuntimeException("Invalid node reference in OSM <way> element: " + ref);
						}
					}
				}
			}
		}
		return result;
	}