Generating XML

How do i generate an XML structure using kxml-java.Any help will be greatly appreciatedBharani
[122 byte] By [bharaniranganath] at [2007-9-26 15:33:48]
# 1

hi,

You can parse an xml file using kxml.

Ex: If your midlet request a servlet which generates an xml structure output then you can use the kxml parser to parse the output and you can display the data.

check these link http://www.ericgiguere.com/techtips/

Download XMLTest.zip and play with that.

GoodLuck.

K0KA at 2007-7-2 18:23:32 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
thanks for your reply.I have done the parsing part, but generating xml using java is the problem
bharaniranganath at 2007-7-2 18:23:33 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

This is the code I've got from somewhere and tried. Works just fine:

Element root = new Element();

root.setName("form");

root.setAttribute(new Attribute("name","Frm-All-03"));

Element e = new Element();

e.setName(Cut Block);

e.addChild(Xml.TEXT,"23/123");

root.addChild(Xml.ELEMENT,e)

System.out.println("XML doc:\n" + root.toString());

Output:

<form name="Frm-All-03">

<Cut Block>23/123</Cut Block>

</form>

The problem is, you cannot build a document with 30 nodes if you have 2MB handheld. Heap runs out of space. So, you may want to write XML to string "manually instead.

Any thoughts?

Stan Berka

Pope & Talbot

stanberka at 2007-7-2 18:23:33 > top of Java-index,Java Mobility Forums,Java ME Technologies...