1

Storage, Network Connections, and Parsing have been optimized/added to the new LWUIT 1.5, but some of us novices still don't know how to use the classes.

I am trying to do the following:
1. connect to the network - send username and password to an online page
2. parse the returned XML results and store them.

Can someone please help me by giving me a short example?

gnat
  • 6,213
  • 108
  • 53
  • 73
Daydah
  • 372
  • 7
  • 20

1 Answers1

3

There are several examples of how to do the former, see the Browser demo, Chat demo (from Chen's incubator directory) & makeover demo.

Login depends on the method you are using to login, e.g. basic authentication just requires a user header with the appropriate values. You can add a header using NetworkManager.addDefaultHeader().

There is indeed a lack of XML parsing tutorials but generally this should be relatively easy.

XMLParser p = new XMLParser();
Element e = p.parse();
Vector children = e.getChildren(); 
Hashtable attributes = e.getAttributes();

To store XML I would just store the XML String itself since LWUIT doesn't provide the facility to save parsed XML data.

Storage.getInstance().writeObject("NameOfObject", xmlString);
String xmlString = Storage.getInstance().readObject("NameOfObject");
Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Thanks Shai! I have been able to implement the network connection successfully - I was even able to add a Button to Cancel the connection to the waitscreen Dialog, but there is a small cause for worry. I keep getting the InterruptedException. Will that affect the application adversely? – Daydah Dec 12 '11 at 06:27
  • That's a separate question but I'm guessing its the timeout of the LWUIT4IO code. Since there is no way to timeout a connection in J2ME we use tricks such as thread interrupt invocations. – Shai Almog Dec 15 '11 at 05:14
  • Thanks! Will look into it asap – Daydah Dec 15 '11 at 07:07