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. Problem with HTTP connection

Hi I am trying to establish the connection between mobile and PC.I am
running server program on PC, when I run the below code server not
displaying any response message.When I send the request from mobile
browser server displaying response message. I am working on
SDK_1.1.Please suggest me on program

public class HTTPPostExample extends Activity {
public void onCreate(Bundle icicle) {
catch(Exception e)
public void httpPostImage() throws Exception {

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("");

//File file = new File("/data/data/org.emrah/icon.png");
// InputStreamEntity reqEntity = new InputStreamEntity(new
FileInputStream(file), -1);


Header[] headers = new BasicHeader[2];
headers[0] = new BasicHeader("Accept","application/xml");
headers[1] = new BasicHeader("Content-type", "application/x-www-form-


System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();


2. findViewById() returns NULL

I was getting a null exception in my onCreate() until I found that I
had to move that method call _after_ the
setContentView(R.layout.main), just in case anyone else has this same
problem. Don't understand the reason why, but just in case anyone gets
this (and then googles for it), this is a possible cause.


3. Multiple Instances of App Running When Home + Restart

4. Web Browser stop Selection

5. How to receive NEW_OUTGOING_CALL?

6. 2D accleration, request OpenGL

7. UberColorPicker Demo