Editing XML files using DOM in Android

by rajesh » Thu, 12 Mar 2009 14:56:05 GMT

Sponsored Links
 Hi all ,
I am developing an application where i need to update a value in an
XML file according to the value entered by the user  and send this
updated file to some server.I am using DOM to do this ..but the
problem is that the function setNodeValue does not seem to
work ....When i print the value after changing the content it gives
the same value as before ...


                         NodeList list = null;
                        DocumentBuilderFactory dbf = 

                        //xmlFile = fileName;
                                DocumentBuilder db = dbf.newDocumentBuilder();
                                InputStream istream = null;
                            xmlDoc2 = db.parse(istream);

                        Element docEle = xmlDoc2.getDocumentElement();
                        list = docEle.getElementsByTagName("Variable");
                         for (int j = 0; j < list.getLength(); j++)
                        Node child = list.item(j);
                        if (child.getNodeType() == Node.ELEMENT_NODE) {
                       Element element=(Element)child;
        System.out.println("This is the text value"+getTextValue



                        catch (Exception e)

This is the setTextValue method :

 private static void setTextValue(Element ele,String tagName,String

        try {
                 NodeList nl = ele.getElementsByTagName(tagName);
                 if (nl != null && nl.getLength() > 0)

                          Element el = (Element) nl.item(0);

                         if (el.getFirstChild() != null)
                              // This is the statement which does not
seem to work


            catch (Exception e)




Please help.... i am not able to understand what is happening .


Other Threads

1. Sony Mylo 2 - other mobile OS ?

I would like to ask if anyone has experience with this hardware. After
about a year and a half I bought it again (quite bad looking), so I
knew what to expect, but I'd like to because of closeness of the OS
there is something else cast (Android, Openmoko or a light Linux
distro) or open system Third party software for, but somehow do not
find a guide or something like that. I found a forum to http://goo.gl/QnTyw
the older type, but there is also mention Mylo 2, including complete
hardware configuration. I found the source code (including kernel).

It is basic on i.MX31 platform.

If anyone could advise I would be happy. Thank you all for your


2. ADT lauout designer D&D is a mega-disaster...


If anyone responsible for ADT is reading then please. please, please
get rid of this damn D&D and restore old, working, old-skool up/down
buttons. The current implementation is so broken that makes the whole
designer quite useless. It's sometimes impossible to rearange items,
as ADT knows "better" what order it shall be. Even worse, if you try
to nest some elements (i.e. 2 TableRows) in other (i.e. LinearLayout)
then 2nd TableRow gets "Dropped" *inside* 1st TableRow and I failed to
drag it out of it. Fortunately I mostly write layout files by hand,
but sometimes visual designer was useful for some soft of quick
sketch. Used to.



3. Security enforcement

4. An interesting architecture question for xml resources

5. Scheduling ideas

6. Sending/receiving text data from remote server

7. Efficient fifo queue for primitive types?