×

Discussion Board

Results 1 to 8 of 8

Hybrid View

  1. #1
    Nokia Developer Champion
    Join Date
    Aug 2010
    Location
    Ahmedabad
    Posts
    299

    Reading XML file using LWUIT

    Hi,

    I want to read an XML file in one of the my LWUIT project. Can anyone share a simple working example of reading XML file using LWUIT?

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: Reading XML file using LWUIT

    The XMLParser class seems to have a handful of public methods only (http://www.developer.nokia.com/Resou...XMLParser.html).
    I think you just need a Reader, instantiate the XMLParser, and invoke parse.
    What happens if you just try something like
    Code:
    String xml="..."; // put some test-XML here
    InputStreamReader isr=new InputStreamReader(new ByteArrayInputStream(xml.getBytes()));
    XMLParser parser=new XMLParser();
    Element root=parser.parse(isr);
    ?

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105

    Re: Reading XML file using LWUIT

    Girish, as LWUIT is about user interface (view), and XML is about (data), when you look at the mode-view-controller (MVC) design pattern, you need to build the controller which sticks these two parts together. Therefore, your question is a bit difficult to understand, for me. However, as you ask about LWUIT, I guess, you want:
    1) suggestion which visual component to use
    2) plus how to fill that up?
    Correct? Or do you have a special component in mind already?

    In the webinar today, you mentioned size of the XML file. Do you worry about heap-size or about visual perception by end-user?
    Last edited by traud; 2013-05-17 at 08:58.

  4. #4
    Nokia Developer Champion
    Join Date
    Aug 2010
    Location
    Ahmedabad
    Posts
    299

    Re: Reading XML file using LWUIT

    Thank you for reply.

    To be more description, for example, I have an XML file having list of Countries, States within countres and cities within the states. So the first screen should show Countries in a list. Once you select country it should show states within that country and accordingly cities after selecting state in third screen. All these data will reside in a single XML file. I got to know that LWUIT has some inbuilt functionality to access XML files and I want to try it out. The XML file may be more than 1 MB in size.

    I am new to play with data in J2ME hence asking this question. Hope you could get my point. A simple example can solve my project problem. :-)

    Thank you for support.
    Quote Originally Posted by traud View Post
    Girish, as LWUIT is about user interface (view), and XML is about (data), when you look at the mode-view-controller (MVC) design pattern, you need to build the controller which sticks these two parts together. Therefore, your question is a bit difficult to understand, for me. However, as you ask about LWUIT, I guess, you want:
    1) suggestion which visual component to use
    2) plus how to fill that up?
    Correct? Or do you have a special component in mind already?

    In the webinar today, you mentioned size of the XML file. Do you worry about heap-size or about visual perception by end-user?

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    678

    Re: Reading XML file using LWUIT

    wizard_hu_ response showed you how to basically use the lwuit XMLParser class (from there its just traversing the nodes in the elements)
    HOWEVER (and this is a big however) if i remember correctly lwuit's xmlparser is a DOM based XML parser which basically means that it loads all the data to memory when it start parsing the xml file which could result in a OOM exception for you if your xml data is large (you said over 1MB) and Series40 devices have normally upto 2MB heap and i bet you have other stuff in your program that takes up memory.
    So my suggestion to you which be to choose a different XML parser which isnt DOM based (there are some stax xml parsrers but my favorite is actually an implementation of XML PULL API which is the kXML2 - just google for it and u'll find it)

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Reading XML file using LWUIT

    hello girispadia,

    i generally use the SAXParser available with j2me, it works very neat let me know if you need some code examples !!

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105

    Re: Reading XML file using LWUIT

    And when everything works, consider to go for kXML/WBXML. This saves a lot of heap and transmission of data.

  8. #8
    Nokia Developer Champion
    Join Date
    Aug 2010
    Location
    Ahmedabad
    Posts
    299

    Re: Reading XML file using LWUIT

    Quote Originally Posted by traud View Post
    And when everything works, consider to go for kXML/WBXML. This saves a lot of heap and transmission of data.
    Thank you all for the replies. I will check one by one.

Similar Threads

  1. Latest lwuit jar file
    By kumarv75 in forum Mobile Java General
    Replies: 1
    Last Post: 2010-07-23, 11:30
  2. Replies: 2
    Last Post: 2007-12-28, 15:53
  3. Replies: 3
    Last Post: 2007-11-17, 10:31
  4. Reading a .txt file from jar without knowing the size of the file !
    By ionutianasi in forum Mobile Java General
    Replies: 12
    Last Post: 2004-06-24, 00:27
  5. reading text file from a jar file -> file not found!
    By iecomdev in forum Mobile Java General
    Replies: 1
    Last Post: 2002-09-30, 12:27

Posting Permissions

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