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 ...

Code:

                         NodeList list = null;
                        DocumentBuilderFactory dbf = 
DocumentBuilderFactory.newInstance();


                        //xmlFile = fileName;
                        try
                        {
                                DocumentBuilder db = dbf.newDocumentBuilder();
                                InputStream istream = null;
           istream=(this.mCtx).getResources().openRawResource
(R.raw.currencyconverter);
                            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;
                       setTextValue(element,"contentvalue","1000");
        System.out.println("This is the text value"+getTextValue
(element,"contentvalue"));


                        }
                    }

                        }

                        catch (Exception e)
                        {
                                e.printStackTrace();

                        }
This is the setTextValue method :

 private static void setTextValue(Element ele,String tagName,String
Value)
         {


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

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

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

                         }

                 }
        }
            catch (Exception e)
            {

             e.printStackTrace();

            }

         }



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


--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. unix domain socket : permission denied issue

hi,

   I have an Command Line Interface application. This application is
dependent on a shared library in which it creates a unix domain
socket. This is succesful scenario.

but if i call the same Shared Library from the Android  UI, it gives
the following error..

Create_Unix_Domain_Socket | unlink(): Permission denied
Create_Unix_Domain_Socket | bind() failed: Permission denied

we have given the following permissions in Manifest file:

      <uses-permission android:name="android.permission.BLUETOOTH" />
      <uses-permission
android:name="android.permission.BLUETOOTH_ADMIN" />
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission
android:name="android.permission.BIND_INPUT_METHOD" />
      <uses-permission
android:name="android.permission.BIND_APPWIDGET" />
      <permission-group android:name="android.permission-
group.NETWORK" />

What other permissions are required to be given form the android side
or any other sugestion.

Thanks in advance.

2. rtsp error (Youtube's rtsp stream)

hi all,

I was tried for rtsp stream for a long time,
finally I could success to play the rtsp stream from mobile Youtube
website,
http://m.youtube.com/
my approach is to copy the stream link and paste it in my code,
then, there are sometimes success to work(play) on Android and
sometimes
will not.
I can't figure out why? is something wrong about Youtube server ?
because my code is just the same, and only change is the stream link
url.
I used VideoView widget and my Android platform is sdk 1.5 and under
x86-based,
so I really want to know why and how can I solved for this.

this is the logcat when I can't work for the video stream.
thanks!!!

=======================================================
W/PlayerDriver( 2116): Using generic video MIO
E/PlayerDriver( 2116): Invalid percentage buffer size 8 (expected 4)
E/PlayerDriver( 2116): Invalid percentage buffer size 8 (expected 4)
E/PlayerDriver( 2116): Invalid percentage buffer size 8 (expected 4)
E/PlayerDriver( 2116): Invalid percentage buffer size 8 (expected 4)
E/PlayerDriver( 2116): Invalid percentage buffer size 8 (expected 4)
E/PlayerDriver( 2116): Invalid percentage buffer size 8 (expected 4)
E/PlayerDriver( 2116): Invalid percentage buffer size 8 (expected 4)
I/ServiceManager( 2112): service 'media.audio_flinger' died
W/MediaPlayer( 3344): MediaPlayer server died!
E/MediaPlayer( 3344): error (100, 0)
E/MediaPlayer( 3344): Error (100,0)
I/ServiceManager( 2112): service 'media.camera' died
D/VideoView( 3344): Error: 100,0

3. Upgrading code to 2.1

4. Get name of current ring tone

5. How to navigate from one page to another?

6. capturing the encoded audio data read by the PV

7. how can i make any service running when the phone is switched on just after the booting.