Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to install plugin in the eclipse?

843834Sep 19 2007 — edited May 6 2009
Hi all,

I made a download the KXML plugin (http://prdownloads.sourceforge.net/kxml/kxml2-min-2.2.2.jar?download), but I can't to install and use this plugin for to read XML files. For example: I need to import org.kxml2.io.KXmlParser. I put the downloaded file in the folder plugins of eclipse and I use the eclipse for develop with J2ME.
I read one article that it teaches to read XML files using the KXML API, see below:

XML File example:
<?xml version="1.0" encoding="UTF-8"?>
<list>
<person>
<name>Person 1</name>
<phone>Number 1</phone>
</person>
<person>
<name>Person 2</name>
<phone>Number 2</phone>
</person>
</list>

Source code of MIDlet
import �
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class XMLParserMidlet extends MIDlet {

Form form = new Form("Persons");

protected void startApp() throws MIDletStateChangeException {

InputStream in = getClass().getResourceAsStream("person.xml");

try {
Display.getDisplay(this).setCurrent(form);
parser(in);
} catch (Exception e) {
e.printStackTrace();
}
}
private void parser(InputStream in) throws Exception {

//begin the XMLParser
KXmlParser parser = new KXmlParser();

parser.setInput(new InputStreamReader(in));
parser.nextTag();

//it locates in the tag <list>
parser.require(XmlPullParser.START_TAG, null, "list");

//while is different END_TAG
while (parser.nextTag () != XmlPullParser.END_TAG) {

//put in the tag <person>
parser.require(XmlPullParser.START_TAG, null, "person");

parserPerson(parser);
form.append("\n");

parser.require(XmlPullParser.END_TAG, null, "person");

}

parser.require(XmlPullParser.END_TAG, null, "list");
parser.next();

parser.require(XmlPullParser.END_DOCUMENT, null, null);

}

private void parserPeerson(KXmlParser parser) throws Exception {

//While is different of </person>
while (parser.nextTag() != XmlPullParser.END_TAG) {
//put in one tag "START". Ex: <name> ou <phone>

parser.require(XmlPullParser.START_TAG, null, null);

String name = parser.getName();

String text = parser.nextText();

System.out.println("Tag: " + name + " -> " + text);

//add the text in the Form
form.append(text);

//put in the and of tag </name> or </phone>

parser.require(XmlPullParser.END_TAG, null, name);

}

}
//the other classes that is necessary
pauseApp�

destroyApp�

}


thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 3 2009
Added on Sep 19 2007
2 comments
254 views