Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
J2ME Kxml Example 
 

This is the simple kxml application, In this application we'll show you how to work with kxml parser and how to parse the xml file in the midlet .

 

J2ME Kxml Example

                         

This is the simple kxml application, In this application we'll show you how to work with kxml parser and how to parse the xml file in the midlet . 

In this section we take the following steps:

  • We  create an employee.xml file, in which we have four tags that is : name, city, state and designation. 
  • We  use the XmlParser in our MIDlet to access the value of xml file and print on the j2me console. 
  • We manipulates the DOM to parse the xml file.

Manipulating the DOM is a simple way of interacting with XML, where the entire XML tree is parsed into a node structure. The XML tree  resides in memory and you can traverse the tree programmatically.

 

The Entire Application is as follows:

 

Source code of KXMLExample.java

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

public class KXMLExample extends MIDlet {
  XmlParser parser = null;
  Document doc = new Document();
  public String emp = "/employee.xml";

  protected void startApp(){
    try {
      InputStream in = this.getClass().getResourceAsStream(emp);
      InputStreamReader is = new InputStreamReader(in);
      parser = new XmlParseris );
      doc.parseparser );
      parser = null;
    catch (IOException ioe) {
      System.err.println(ioe);
      ioe.printStackTrace();
      parser = null;
      doc = null;
      return;
    
    Element root = doc.getRootElement();
    int child_count = root.getChildCount();

    for (int i = 0; i < child_count ; i++ ) {
      if (root.getType(i!= Xml.ELEMENT) {
        continue;
      }

      Element element = root.getElement(i);
      if (!element.getName().equals("details")) {
        continue;
      }

      System.out.println("----------[ EMP-DETAILS ]----------");
      int address_item_count = element.getChildCount();

      for (int j = 0; j < address_item_count ; j++) {
        if (element.getType(j!= Xml.ELEMENT) {
          continue;
        }
        Element item = element.getElement(j);
        System.out.printlnitem.getName() ": " + item.getText(0));
        item = null;
      }
      System.out.println("-----------------------------------\n");
      element = null;
    }    
  }

  protected void pauseApp(){}

  protected void destroyApp(boolean unconditional){
    notifyDestroyed();
  }
}

Output:

The Complete Source Code Here: Download

                         

» View all related tutorials
Related Tags: c xml events parsing list orm data form event io struct parse count parser format callbacks gis callback vi structure

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.