Skip to main content

how can i modify file xml into midlet

2 replies [Last post]
voilemiss
Offline
Joined: 2009-05-19
Points: 0

String fileName = "file:///root1/books.xml";
DataOutputStream os = null;

FileConnection fc = null;
try {
fc = (FileConnection) Connector.open(fileName);
Document d = new Document();

Element catalog = d.getElement("", "catalog");

Element book = catalog.getElement("", "book");

Element title = book.getElement("", "title");
title.removeChild(0);
title.addChild(Element.TEXT, "Spider World: The Tower");

Element publish = book.getElement("", "publish-date");
publish.removeChild(0);
publish.addChild(Element.TEXT, "1987");

os = fc.openDataOutputStream();
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(os, "UTF-8");
d.write(serializer);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}
catch (Throwable t) {
System.out.println("Exception:"+t);
t.printStackTrace();
}

}

My file xml

<?xml version='1.0' encoding='UTF-8' ?>

]>

Colin Wilson
The Mind Parasites
Horror novel, Science fiction novel
1967

My proble that when i run

Exception:java.lang.RuntimeException: Element {}catalog not found in org.kxml2.kdom.Document@1cb37664
java.lang.RuntimeException: Element {}catalog not found in org.kxml2.kdom.Document@1cb37664
at org.kxml2.kdom.Node.getElement(+84)
at Midlet.startApp(+33)
at javax.microedition.midlet.MIDletProxy.startApp(MIDletProxy.java:43)
at com.sun.midp.midlet.Scheduler.schedule(Scheduler.java:374)
at com.sun.midp.main.Main.runLocalClass(Main.java:466)
at com.sun.midp.main.Main.main(Main.java:120)

PLEASE HELP ME

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
annaharris
Offline
Joined: 2012-04-08
Points: 0

Please explain the issue in words because Nobody has got so much of time that he/she will read the total code and then read the exceptions list.

magicsimon
Offline
Joined: 2012-03-14
Points: 0

This might help.

www.w3schools.com/xml/xml_examples.asp

Use it myself from time to time.