BlackBerry Forums Support Community

BlackBerry Forums Support Community (
-   Developer Forum (
-   -   XML serializer: XML -> myClass (

hibbert 02-19-2009 04:48 AM

XML serializer: XML -> myClass
in there is a way to serialize a class to a XML-document and the other way round.
Is there also a simple way to do this in java for BlackBerry? I get a XML-document such like this one here:

Now I've got my Class user:

class user {
public String Name;
public String Vorname;
user() {}

And now i want to pasre the XML-String and after parsing I want to have a Vector. The Vector should contain n elements of class user, created from the XML-String.

So is there a Simple way to do this? Is there a kind of function which I can use for other classes also??

I hope you know what i want to do, and i hope that someone can help me :)

thanks, hibbert

hippocamp software 02-19-2009 05:11 AM

use the native sax parser: net.rim.device.api.xml.parsers.SAXParser

SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();

hibbert 02-19-2009 05:21 AM

Ok thanks, i will take a look at it :)

But the only Examples i could find doesn't return a class or something like that or I don't understand what is done there, so it really doesn't help me at the moment. maybe you can give me another tip how to complete this :)

thanks again hibbert

hibbert 02-19-2009 06:10 AM

ok, this is what i have got (so far)
PHP Code:

public class frmXML extends UiApplication{
MainScreen mainScreen null;
    private final class 
myScreen extends MainScreen {}
    public static 
void main(Stringxxx91;xxx93; args) {
frmXML theApp = new frmXML();
InputStream stringToStream(String _text) {
InputStream is = new ByteArrayInputStream(_text.getBytes("UTF-8"));

frmXML() {
MainScreen mainScreen = new myScreen();
SAXParserFactory factory SAXParserFactory.newInstance();
OutputStreamWriter out;      
String xmlString "<data><user><name>Name1</name><vorname>Vorname1</vorname></user><user><name>Name2</name><vorname>Vorname2</vorname></user></data>";
  try {

out = new OutputStreamWriter(System.out"UTF8");
SAXParser saxParser factory.newSAXParser();
saxParser.parse(new InputSource(stringToStream(xmlString), new clsUser()));
    } catch (
Throwable err) {
err.printStackTrace ();
package XML;

String Name "";
String Vorname "";
clsUser() {}

but i get this error here:

cannot find symbol
symbol : constructor InputSource(,XML.clsUser)
location: class org.xml.sax.InputSource
saxParser.parse(new InputSource(stringToStream(xmlString), new clsUser()));
^ (under new InputSource)
1 error
maybe someone can help me, and how do i create my vector??

thanks hibbert

All times are GMT -5. The time now is 01:14 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.