l = doc.getElementsByTagName("layer"); for (int i = 0; (item = l.item(i)) != null; i++) { if (item.getParentNode() == mapNode) { MapLayer layer = unmarshalLayer(item); if (layer != null) { map.addLayer(layer);
l = mapNode.getChildNodes(); for (int i = 0; i < l.getLength(); i++) { Node sibs = l.item(i); if (sibs.getParentNode() == mapNode) { if(sibs.getNodeName().equals("layer")) { MapLayer layer = unmarshalLayer(sibs); if (layer != null) { map.addLayer(layer); } }else if(sibs.getNodeName().equals("objectgroup")) { MapLayer layer = unmarshalObjectGroup(sibs); if (layer != null) { map.addLayer(layer); }
    private void buildMap(Document doc) throws Exception {        Node item, mapNode;        NodeList l, mapNodeList;        NamedNodeMap nnm;        Tile tile;        mapNodeList = doc.getElementsByTagName("map");        for (int itr = 0; (mapNode = mapNodeList.item(itr)) != null; itr++) {            // Get the map dimensions and create the map            int mapWidth = getAttribute(mapNode, "width", 0);            int mapHeight = getAttribute(mapNode, "height", 0);            if (mapWidth > 0 && mapHeight > 0) {                map = new Map(mapWidth, mapHeight);            } else {                // Maybe this map is still using the dimensions element                l = doc.getElementsByTagName("dimensions");                for (int i = 0; (item = l.item(i)) != null; i++) {                    if (item.getParentNode() == mapNode) {                        mapWidth = getAttribute(item, "width", 0);                        mapHeight = getAttribute(item, "height", 0);                        if (mapWidth > 0 && mapHeight > 0) {                            map = new Map(mapWidth, mapHeight);                        }                    }                }            }            if (map == null) {                throw new Exception("Couldn't locate map dimensions.");            }            // Load other map attributes            String orientation = getAttributeValue(mapNode, "orientation");            int tileWidth = getAttribute(mapNode, "tilewidth", 0);            int tileHeight = getAttribute(mapNode, "tileheight", 0);            if (tileWidth > 0) {                map.setTileWidth(tileWidth);            }            if (tileHeight > 0) {                map.setTileHeight(tileHeight);            }            if (orientation != null) {                setOrientation(orientation);            } else {                setOrientation("orthogonal");            }            // Load the properties            l = doc.getElementsByTagName("property");            for (int i = 0; (item = l.item(i)) != null; i++) {                if (item.getParentNode() == mapNode) {                    map.addProperty(getAttributeValue(item, "name"),                            getAttributeValue(item, "value"));                }            }            // Load the tile sets            l = doc.getElementsByTagName("tileset");            for (int i = 0; (item = l.item(i)) != null; i++) {                if (item.getParentNode() == mapNode) {                    map.addTileset(unmarshalTileset(item));                }            }            // Load the layers            l = doc.getElementsByTagName("layer");            for (int i = 0; (item = l.item(i)) != null; i++) {                if (item.getParentNode() == mapNode) {                    MapLayer layer = unmarshalLayer(item);                    if (layer != null) {                        map.addLayer(layer);                    }                }            }            // Load the objects            l = doc.getElementsByTagName("object");            for (int i = 0; (item = l.item(i)) != null; i++) {                if (item.getParentNode() == mapNode) {                    map.addObject(unmarshalObject(item));                }            }        }    }