public List<OSMWay> readWaysFromOSMFile(Document doc) {
		List<OSMWay> osmWays = new ArrayList<OSMWay>();

		NodeList waysList = doc.getElementsByTagName("way");
		// NOTICE: don't put this into condition part of a for-loop,
		//         because getLength() is a O(n) function.
		int length = waysList.getLength();
		
		// load all ways from the osm file
		for (int i = 0; i < length; i++) {
			Node item = waysList.item(i);
			NamedNodeMap attrsMap = waysList.item(i).getAttributes();
			String wayID = attrsMap.getNamedItem("id").getNodeValue();

			// read the 'tags' and 'refs' of this way
			Map<String, String> tags = readTagMapFromOSMFile(item);
			List<String> refs = readRefsOfWayFromOSMFile(item);

            // String highway = tags.get("highway");
            // String railway = tags.get("railway");
            
            if (tags.get("highway") == null) continue;
            
            String[] labels = tags.get("highway").split("_");
            String highway = labels[0];
            
            int level = 0;
            
            if      (highway.equals("motorway"))    { level = 1; } 
            else if (highway.equals("primary"))     { level = 2; } 
            else if (highway.equals("secondary"))   { level = 3; } 
            else if (highway.equals("tertiary"))    { level = 4; } 
            else if (highway.equals("trunk"))       { level = 5; } 
            else if (highway.equals("residential")) { level = 6; } 
            
            // if (((highway != null) 
            //   && !highway.equals("footway")
            //   && !highway.equals("cycleway")
            //   && !highway.equals("pedestrian")
            //   // if want to only use primary streets, uncomment this 
            //   // condition.                   
            //   // && !highway.equals("residential") 
            //   && !highway.equals("service") 
            //   && !highway.equals("unclassified") 
            //               && !highway.equals("platform")
            //   && !highway.equals("access_ramp")
            //                 && !highway.equals("steps")
            //   && !highway.equals("path"))) {
            //   // || ((railway != null) && !railway.equals("tram"))) {
            //     osmWays.add(new OSMWay(wayID, refs, tags));
            // }
            
            if (level != 0) {
			    osmWays.add(new OSMWay(wayID, refs, tags, level));
            }
		}

		return osmWays;
	}