You Are Here:

Community: Developer Discussion Boards

#1 Old xml with j2me - 2006-04-27, 07:45

Join Date: Nov 2005
Posts: 33
yafy
Offline
Registered User
Hi folks ,

Im a biginner in xml parsing .I have my "spin.xml" file in E dir. Im using Netbeans 5.0 for my game development. i want to parse the xml file to get its content into my mobile or emulator. Please tell me the basic steps i have to follow. I got one sample program for xml parsing which uses

FileConnection fc = (FileCOnnection)Connector.open("file:///root1/helloword.xml");

So i replaced it by

FileConnection fc = (FileCOnnection)Connector.open("file:///E:/spin.xml");

But its throwing IO EXP: "Root not accesible"

plz suggest where(which folder) should i store the xml file to get it in emulator and phone.

thanks in advance....

yafy.
Reply With Quote

#2 Old Re: xml with j2me - 2006-04-28, 16:38

Join Date: Dec 2005
Posts: 1,886
Location: Brazil
Send a message via MSN to juarezjunior Send a message via Skype™ to juarezjunior
juarezjunior's Avatar
juarezjunior
Offline
Forum Nokia Champion
Hi yafi,

Well, if your target device implements JSR-75 then you should go that way. Otherwise, include you XML file as a resource within your JAR file.

Regarding your doubts related to directories and files i advise you to read this doc:

Introduction To The FileConnection API (With Example) v1.1
http://www.forum.nokia.com/info/sw.n..._v1_1.zip.html

Take a look at the doc below for good information regarding XML parsing in JME:

XML in J2ME
http://trix2.cellmania.com/downloads...E_20060301.pdf

Forum Nokia also has a document that briefly discuss the JSR-172 XML parsing optional package (the standard way). Check it out, page 6.

MIDP: Web Services API Developer's Guide (With Example)
http://www.forum.nokia.com/info/sw.n..._v1_0.zip.html

I hope it helps!

BR,

Juarez
Reply With Quote

#3 Old Re: xml with j2me - 2006-04-28, 17:54

Join Date: Mar 2006
Posts: 556
Location: Phoenix, AZ. USA
Jason Glass's Avatar
Jason Glass
Offline
Super Contributor
and if you are using netbeans and WTK emualtor, you need to find the emulators root file system on your PC's file system

for example in Win2k and XP, mine is
D:\Documents and Settings\Jay\.netbeans\4.1\emulators\wtk22_win\emulator\wtk22\appdb\DefaultColorPhone\filesystem\root1

using e of your hard drive, wont work, if thats what your trying, note the bolded above, this is where the emulators file system begins

so you would place your xml file in there


Jason Glass
http://IChiBanComputers.Com
Reply With Quote

#4 Old Thumbs up Re: xml with j2me - 2009-06-04, 08:57

Join Date: Jun 2009
Posts: 4
csaimohanb
Offline
Registered User
spin.xml
========
<details>
<title>abc</title>
<description>hai</description>
</details>




ParseXML.java
=============

import java.io.*;
import org.kxml.*;
import org.kxml.parser.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.Displayable;

public class ParseXML extends MIDlet implements CommandListener {
private Command exit;
private Command xml;
private Display display;
private static TextBox t;
private static String textBoxString = "";
private String xmlStr = "/spin.xml";


public ParseXML() {
display = Display.getDisplay( this );
exit = new Command( "Exit", Command.EXIT, 2 );
xml = new Command( "XML", Command.SCREEN, 1 );

}

public void startApp() {
t = new TextBox( "MIDlet XML", "kXML", 256, 0 );
t.addCommand( exit );
t.addCommand( xml );
t.setCommandListener( this );
display.setCurrent( t );
}

public void pauseApp() { }

public void destroyApp(boolean unconditional) { }

public void commandAction(Command c, Displayable s) {
if ( c == exit ) {
destroyApp( false );
notifyDestroyed();
} else if ( c == xml ) {
try {
viewXML();
t.removeCommand(xml);
} catch( Exception e ) {
e.printStackTrace();
}
}
}

public void viewXML() throws IOException {
try {
byte[] xmlByteArray = xmlStr.getBytes();
ByteArrayInputStream xmlStream = new ByteArrayInputStream( xmlByteArray );
InputStreamReader xmlReader = new InputStreamReader( xmlStream );
XmlParser parser = new XmlParser( xmlReader );
try {
traverse( parser, "" );
} catch (Exception exc) {
exc.printStackTrace();
}
return;
} catch ( IOException e ) {
return ;
} finally {
return ;
}
}

public static void traverse( XmlParser parser, String indent ) throws Exception{
boolean leave = false;
String title = new String();
String desc = new String();
do {
ParseEvent event = parser.read ();
ParseEvent pe;
switch ( event.getType() ) {
case Xml.START_TAG:
if ("title".equals(event.getName())){
pe = parser.read();
title = pe.getText();
}

if ("description".equals(event.getName())){
pe = parser.read();
desc = pe.getText();
}
textBoxString = title + " " + desc;
traverse( parser, "" ) ;
break;

case Xml.END_TAG:
leave = true;
break;

case Xml.END_DOCUMENT:
leave = true;
break;

case Xml.TEXT:
break;

case Xml.WHITESPACE:
break;

default:
}
} while( !leave );

t.setString( textBoxString );
}
Reply With Quote

#5 Old Re: xml with j2me - 2009-06-04, 09:36

Join Date: Apr 2007
Posts: 1,757
Tiger79's Avatar
Tiger79
Online
Forum Nokia Champion
hehe,
you did notice it was a 3 year old thread right ? ;)
Reply With Quote

#6 Old Re: xml with j2me - 2009-06-04, 12:45

Join Date: Feb 2006
Posts: 689
soku123
Offline
Super Contributor
Hi,
try using the SAX parser.

Thanks
Soku
Reply With Quote

#7 Old Re: xml with j2me - 2009-06-04, 12:56

Join Date: Apr 2007
Posts: 1,757
Tiger79's Avatar
Tiger79
Online
Forum Nokia Champion
lol,
I guess some people just dont read :P
Reply With Quote

#8 Old Re: xml with j2me - 2009-06-08, 06:29

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Quote:
Originally Posted by Tiger79 View Post
lol,
I guess some people just dont read :P
Tiger,rather they keep on positng


Thanks

R a j - The K e r n e l
Reply With Quote

#9 Old Re: xml with j2me - 2009-06-12, 15:04

Join Date: Jan 2008
Posts: 385
manjul_saini's Avatar
manjul_saini
Offline
Regular Contributor
Try this, use kxml2


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.397.79
*/

import java.io.InputStreamReader;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;

/**
* @author Manjul
*/
public class AddressMidlet extends MIDlet implements Runnable
{
InputStreamReader ip;
KXmlParser parser;
Thread t;
String tag,text;

public void startApp()
{
t=new Thread(this);
t.start();
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void run()
{
try{
ip= new InputStreamReader(this.getClass().getResourceAsStream("/address.xml"));
parser= new KXmlParser();
parser.setInput(ip);

parser.nextTag();
parser.require(XmlPullParser.START_TAG, null, "address_book");
System.out.println("111111111");
while(parser.nextTag()!=XmlPullParser.END_TAG)
{
parser.require(XmlPullParser.START_TAG, null , "address");

while(parser.nextTag()!=XmlPullParser.END_TAG)
{
tag=parser.getName();
text=parser.nextText();
System.out.println(tag+" <<<::>>> "+text);
parser.require(XmlPullParser.END_TAG, null , tag);
}
}

parser.require(XmlPullParser.END_TAG,null, "address_book");
parser.next();
parser.require(XmlPullParser.END_DOCUMENT,null,null);
}catch(Exception e){System.out.println("errorrrrr "+e);e.printStackTrace();}
}

}


address.xml look like this


<address_book>
- <address>
<name>Robert Cadena</name>
<street_1>5555 Fake Street</street_1>
<street_2>Suit 202</street_2>
<city>Fake City</city>
<state>CA</state>
<zipcode>900099</zipcode>
</address>
- <address>
<name>Fake Name</name>
<street_1>3232 Another Street</street_1>
<city>Another City</city>
<state>TX</state>
<zipcode>79999</zipcode>
</address>
- <address>
<name>Manjul</name>
<street_1>1119/5</street_1>
<city>Gurgaon</city>
<state>Haryana</state>
<zipcode>122055</zipcode>
</address>
</address_book>


Thanks and Regards,
Manjul.
Reply With Quote

#10 Old Smile Re: xml with j2me - 2009-06-12, 15:06

Join Date: Jan 2008
Posts: 385
manjul_saini's Avatar
manjul_saini
Offline
Regular Contributor

Hi all,

this is common mistake done by every one, guys keep on accessing file system simply using File(.....)

it is only possible by using jsr75 else not.

or supply a file with jar.




Thanks and Regards,
Manjul.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Using kxml package in J2ME!! PLEASE HELP ajayluthria Mobile Java General 3 2007-03-21 06:43
help on linking XML databases to J2ME. yenpaul2001 Mobile Java General 0 2006-01-22 19:43
XML Schema parser for J2ME??? Pepper_91 Mobile Java General 1 2005-10-11 01:37
download/upload xml from-to server in j2me freezenik Mobile Java Networking & Messaging & Security 0 2005-01-26 06:00
J2ME Polish Version 1.0 RC6 enough Mobile Java General 1 2004-07-20 12:25

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d127641X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZgamesQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ