public void loadTextureDataFromXML(String filename) throws Exception { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new File(filename)); //Get root element Element root = doc.getRootElement(); if(root.getQualifiedName().equals("textures")){ //Create list from it's children. Since JDom is 1.4 java we have to cast the list type. List textures = (List ) root.getChildren(); int w, h, c, r, start, end, loopto, number; boolean loop; double fps; //Go trough the children and from each, create texture with attributes. for (Element element : textures) { //Let's get the attributes of this child String textureName = element.getAttributeValue("name"); String textureFileName = element.getAttributeValue("fileName"); w = Integer.parseInt(element.getAttribute("xSize").getValue()); h = Integer.parseInt(element.getAttribute("ySize").getValue()); c = Integer.parseInt(element.getAttribute("columns").getValue()); r = Integer.parseInt(element.getAttribute("rows").getValue()); System.out.println("Name: " + textureName + " From file: " + textureFileName + " Widht: " + w + " Height: " + h); //Let's create a new texture from this childs attributes and put it into a map. Texture texture = new Texture(1, textureName, textureFileName, w, h, r, c); //Get all children of this texture (animations) and parse animations. List animations = (List ) element.getChildren(); //Temporary list Vector animationsList = new Vector(); //Go trough the list of the animations and create them for this texture. for (Element animation : animations) { String animationName = animation.getAttributeValue("name"); start = Integer.parseInt(animation.getAttribute("start").getValue()); end = Integer.parseInt(animation.getAttribute("end").getValue()); loopto = Integer.parseInt(animation.getAttribute("looto").getValue()); number = Integer.parseInt(animation.getAttribute("number").getValue()); fps = Double.parseDouble(animation.getAttribute("fps").getValue()); loop = Boolean.parseBoolean(animation.getAttributeValue("loop")); animationsList.add(new Animation(animationName, start, end, loopto, fps, number)); } this.map.put(textureName, texture); } } else System.out.println("Invalid document! '" + filename + "' didn't have root element 'texture'."); }