private static void addImgToXmlData(String imgName, String galleryName) {
        NodeList nList = null;
        try {
            File fXmlFile = new File(path);

            DocumentBuilderFactory dbFactory = DocumentBuilderFactory
                    .newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(fXmlFile);

            doc.getDocumentElement().normalize();

            nList = doc.getElementsByTagName("gallery");

            int len = nList.getLength();
            for (int i = 0; i < len; i++) {
                Node nNode = nList.item(i);
                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element) nNode;
                    String name = eElement.getAttribute("name");
                    if (name.equals(galleryName)) {
                        Element img = doc.createElement("image");
                        img.setAttribute("src", imgName);
                        img.setAttribute("effect", "");
                        img.setAttribute("contrast", "");
                        img.setAttribute("sharpness", "");
                        img.setAttribute("moving", "");
                        img.setAttribute("scrollSpeed", "");
                        eElement.appendChild(img);
                    }
                }
            }

            doc.getDocumentElement().normalize();
            TransformerFactory transformerFactory = TransformerFactory
                    .newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            DOMSource source = new DOMSource(doc);
            StreamResult result = new StreamResult(new File(path));
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.transform(source, result);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }