tags:

views:

129

answers:

1

Hi Guys, I have been trying to figure out how to encode and decode stuff in java for almost a day now.

I have followed this example. The problem is when I try to get the XML I have just built in the form of a string, I simply get an empty string. How ever, when I use the 'count' property, it prints the correct amount of nodes I have inserted.

So, what I would like to know is what do I have to do so that I can get the XML string I have just built? This is the code I am using to build the XML string:

    kXMLElement xmlMessage = new kXMLElement();
    xmlMessage.addChild(createElement("Type", String.valueOf(mobileMessage.MESSAGE_TYPE)));
    xmlMessage.addChild(createElement("Source", mobileMessage.source));
    xmlMessage.addChild(createElement("Date", mobileMessage.date));
    xmlMessage.addChild(createElement("Content", mobileMessage.messageContent));

    System.out.println("\n\n" + xmlMessage.toString() + "\n\n");           //This basically prints and empty String.
    System.out.println("Children = " + xmlMessage.countChildren());        //This prints 4

I am using the J2ME version of NanoXML downloaded from here

Any help is appreciated. Thanks.

A: 

That's weird... the code looks like it should work as normal.

Btw, a great alternative for XML parsing and writing for J2ME is kXML (http://kxml.sourceforge.net/).

David Johnson
Yeah I tried that too, but I didn't manage with it either.I ended up writing the xml string myself, I didn't have much to write, I just wanted to automate the XML writing process so that I can eliminate any chances of typos from my side.
npinti