×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Apr 2009
    Location
    Kuala Lumpur
    Posts
    98

    Question Reading and Writing data from/to XML file in J2ME

    Hi,

    I searched all the Internet but i couldn't find my answer. Please, guide me.

    I have XML file with these information:
    <Phone_Numbers xmlns:xs1="http://www.herbal-life.asia">
    <ID>1
    <Number>006012345678</Number>
    </ID>
    <ID>2
    <Number>006012345679</Number>
    </ID>
    </Phone_Numbers>
    Now, in program I want to read these data or add another phone number to this list or delete one.
    what should I do?
    If it's possible give me one sample code.

    Thanks

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Reading and Writing data from/to XML file in J2ME

    Where is the data stored?

    What model(s) of device do you need to support?

    Graham.

  3. #3
    Regular Contributor
    Join Date
    Apr 2009
    Location
    Kuala Lumpur
    Posts
    98

    Re: Reading and Writing data from/to XML file in J2ME

    Quote Originally Posted by grahamhughes View Post
    Where is the data stored?

    What model(s) of device do you need to support?

    Graham.
    Thank you dear Graham,

    the story is: I want to send sms to lots of my customers as an advertise or announce about something. I want to read phone numbers from XML file and transfer it to program and send message to that phone number.
    I've done this project with RMS(Nokia 5800) but RMS has some problems. first, if I delete one record it clears the data but i have blank. it never shift up automatically and if i shift it through program it takes long time. Second, If i use RMS i should enter data within mobile phone. but i want to have record of numbers on my computer.

    now, i want to use XML. why?
    because i enter all of my information in Excel (i can update it regularly), then i can convert it to XML and then transfer it to mobile phone. so, easily i can update this database! and use it in mobile phone.

    This is my first try to learn XML and join it to Java programs. so, because of this i don't know how can i join XML to Java program.

    I forgot to say that, my message is simple Text message ans receiver is simple mobile phones.

    Thanks again.

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Reading and Writing data from/to XML file in J2ME

    You have a slight (and common) misconception about RMS. When you delete a record, you don't end up with a gap. You end up with a record ID that is no longer value. Record IDs are not like an array index. They are more like a primary key. A record's ID never changes, so record ID 2 is always ID 2, even after ID 1 has been deleted.

    There are ways to avoid that issue on RMS. Either:

    1. Store all the data in one big record.

    2. Load all the records into a Vector, update the Vector, delete the record store and create it again with the new data.

    If you store data in XML as a file in the phone's file system, you will run into a whole bunch of security restrictions.

    This article compares file access with RMS, and describes some tricks for using RMS more efficiently. It doesn't describe access files in much detail - go to the end of the document, where you'll find links to other pages.

    Your phone supports JSR 172 for reading XML. This is basically a dumbed-down version of what you get in J2SE. Not all devices support this, but your does (which is why I asked you which devices you needed to support). I can't recommend a specific guide to '172, but it's easy to find plenty of introductions.

    JSR 172 won't help you update XML, it's only a parser. There is no support for managing XML data, only reading it. To write it, you'd have to construct it as a text file.

    So far as sending SMS is concerned, search the forum, there are plenty of threads about this, and I'm sure there are guides in the wiki. Sending an SMS is quite simple, though again, it is subject to security issues.

    When I say "security issues", you will see prompts for confirmation, which cannot easily be switched off. Also, some parts of the file system will be inaccessible, or read-only. You might not have access to the file system root, for example.

    I don't think that tells you everything you need to know, but hopefully points you in the right direction to do some research, try some code, and come back with some more questions!

    Good luck!
    Graham.

  5. #5
    Regular Contributor
    Join Date
    Apr 2009
    Location
    Kuala Lumpur
    Posts
    98

    Wink Re: Reading and Writing data from/to XML file in J2ME

    Thanks dear Graham,

    I've learned a lot of your explanation.

    You are right when you told me ID in RMS will not clear. My problem was this.
    In my program (previous), after adding or deleting a record, the whole of record sorted and if it found iteration cleared one of that. I exchanged blank with * (star) through program.
    Because ID never cleared I had lots of *s in my database (records). I entered 300 numbers while around first 20 was *.

    That was bad thing that I never could remove from RMS and because of this I decided to change it with XML.

    My phone (Nokia 5800) support XML and because I want to read it so, I think I won't have problem. For update of XML, I'll use computer. so, i think this is better way but the only problem as you told me is how can i cope with security issues. I don't khow! )

    One Iranian proverb says: Want is ability.

    Thanks again and sorry for for my poor and Horrible English.

Similar Threads

  1. How can we read the XML file saved in Mobile.
    By rahulkrishna in forum Mobile Java General
    Replies: 7
    Last Post: 2009-08-17, 18:23
  2. Reading and writing to file
    By rkuppala in forum Symbian
    Replies: 6
    Last Post: 2008-03-13, 09:59
  3. Reading and writing from file in j2me????
    By amitsamel in forum Mobile Java General
    Replies: 1
    Last Post: 2007-11-15, 18:44
  4. File reading & writing help, wav file redaing help
    By shubhamlahoti in forum Mobile Java General
    Replies: 6
    Last Post: 2007-06-27, 09:07

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×