Xml, bluetooth, j2me j2se

hello, i have a question: i need to write a client-server application (the client will be running on a mobile phone using j2me and the server on a windows PC) that would communicate using xml documents over a bluetooth connection. My question is: is there a simple way to send and parse documents from client to server and vice versa ?
Thank You in advance.

via sockets

Similar Messages

  • Bluetooth and J2SE?

    Hi
    Sorry if I posted this topic to the wrong group but it seems to match here.
    I would like to prepare quite simple application which searches for active bluetooth devices in range and lists them. I want to develop it for desktop - my laptop in fact so I intend to use J2SE. Main problem is that I do not know where to start and whether or not it is possible (as far as I know under j2me it can be done)?
    Thank you for any help in advance.
    Best regards

    Hello.
    Test this application:
    CLIENT:
    import java.lang.*;
    import java.io.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.bluetooth.*;
    * This class shows a simple client application that performs device
    * and service
    * discovery and communicates with a print server to show how the Java
    * API for Bluetooth wireless technology works.
    public class PrintClient implements DiscoveryListener {
         * The DiscoveryAgent for the local Bluetooth device.
        private DiscoveryAgent agent;
         * The max number of service searches that can occur at any one time.
        private int maxServiceSearches = 0;
         * The number of service searches that are presently in progress.
        private int serviceSearchCount;
         * Keeps track of the transaction IDs returned from searchServices.
        private int transactionID[];
         * The service record to a printer service that can print the message
         * provided at the command line.
        private ServiceRecord record;
         * Keeps track of the devices found during an inquiry.
        private Vector deviceList;
         * Creates a PrintClient object and prepares the object for device
         * discovery and service searching.
         * @exception BluetoothStateException if the Bluetooth system could not be
         * initialized
        public PrintClient() throws BluetoothStateException {
             * Retrieve the local Bluetooth device object.
            LocalDevice local = LocalDevice.getLocalDevice();
             * Retrieve the DiscoveryAgent object that allows us to perform device
             * and service discovery.
            agent = local.getDiscoveryAgent();
             * Retrieve the max number of concurrent service searches that can
             * exist at any one time.
            try {
                maxServiceSearches = Integer.parseInt(
                    LocalDevice.getProperty("bluetooth.sd.trans.max"));
            } catch (NumberFormatException e) {
                System.out.println("General Application Error");
                System.out.println("\tNumberFormatException: " + e.getMessage());
            transactionID = new int[maxServiceSearches];
            // Initialize the transaction list
            for (int i = 0; i < maxServiceSearches; i++) {
                transactionID[i] = -1;
            record = null;
            deviceList = new Vector();
         * Adds the transaction table with the transaction ID provided.
         * @param trans the transaction ID to add to the table
        private void addToTransactionTable(int trans) {
            for (int i = 0; i < transactionID.length; i++) {
                if (transactionID[i] == -1) {
                    transactionID[i] = trans;
                    return;
         * Removes the transaction from the transaction ID table.
         * @param trans the transaction ID to delete from the table
        private void removeFromTransactionTable(int trans) {
            for (int i = 0; i < transactionID.length; i++) {
                if (transactionID[i] == trans) {
                    transactionID[i] = -1;
                    return;
         * Completes a service search on each remote device in the list until all
         * devices are searched or until a printer is found that this application
         * can print to.
         * @param devList the list of remote Bluetooth devices to search
         * @return true if a printer service is found; otherwise false if
         * no printer service was found on the devList provided
        private boolean searchServices(RemoteDevice[] devList) {
            UUID[] searchList = new UUID[2];
             * Add the UUID for L2CAP to make sure that the service record
             * found will support L2CAP.  This value is defined in the
             * Bluetooth Assigned Numbers document.
            searchList[0] = new UUID(0x0100);
             * Add the UUID for the printer service that we are going to use to
             * the list of UUIDs to search for. (a fictional printer service UUID)
            searchList[1] = new UUID("11111111111111111111111111111111", false);
             * Start a search on as many devices as the system can support.
            for (int i = 0; i < devList.length; i++) {
    System.out.println("Length = " + devList.length);
                 * If we found a service record for the printer service, then
                 * we can end the search.
                if (record != null) {
    System.out.println("Record is not null");
                    return true;
                try {
    System.out.println("Starting Service Search on " + devList.getBluetoothAddress());
    int trans = agent.searchServices(null, searchList, devList[i],
    this);
    System.out.println("Starting Service Search " + trans);
    addToTransactionTable(trans);
    } catch (BluetoothStateException e) {
    System.out.println("BluetoothStateException: " + e.getMessage());
    * Failed to start the search on this device, try another
    * device.
    * Determine if another search can be started. If not, wait for
    * a service search to end.
    synchronized (this) {
    serviceSearchCount++;
    System.out.println("maxServiceSearches = " + maxServiceSearches);
    System.out.println("serviceSearchCount = " + serviceSearchCount);
    if (serviceSearchCount == maxServiceSearches) {
    System.out.println("Waiting");
    try {
    this.wait();
    } catch (Exception e) {
    System.out.println("Done Waiting " + serviceSearchCount);
    * Wait until all the service searches have completed.
    while (serviceSearchCount > 0) {
    synchronized (this) {
    try {
    this.wait();
    } catch (Exception e) {
    if (record != null) {
    System.out.println("Record is not null");
    return true;
    } else {
    System.out.println("Record is null");
    return false;
    * Finds the first printer that is available to print to.
    * @return the service record of the printer that was found; null if no
    * printer service was found
    public ServiceRecord findPrinter() {
    * If there are any devices that have been found by a recent inquiry,
    * we don't need to spend the time to complete an inquiry.
    RemoteDevice[] devList = agent.retrieveDevices(DiscoveryAgent.CACHED);
    if (devList != null) {
    if (searchServices(devList)) {
    return record;
    * Did not find any printer services from the list of cached devices.
    * Will try to find a printer service in the list of pre-known
    * devices.
    devList = agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
    if (devList != null) {
    if (searchServices(devList)) {
    return record;
    * Did not find a printer service in the list of pre-known or cached
    * devices. So start an inquiry to find all devices that could be a
    * printer and do a search on those devices.
    /* Start an inquiry to find a printer */
    try {
    agent.startInquiry(DiscoveryAgent.GIAC, this);
    * Wait until all the devices are found before trying to start the
    * service search.
    synchronized (this) {
    try {
    this.wait();
    } catch (Exception e) {
    } catch (BluetoothStateException e) {
    System.out.println("Unable to find devices to search");
    if (deviceList.size() > 0) {
    devList = new RemoteDevice[deviceList.size()];
    deviceList.copyInto(devList);
    if (searchServices(devList)) {
    return record;
    return null;
    * This is the main method of this application. It will print out
    * the message provided to the first printer that it finds.
    * @param args[0] the message to send to the printer
    public static void main(String[] args) {
    PrintClient client = null;
    * Validate the proper number of arguments exist when starting this
    * application.
    if ((args == null) || (args.length != 1)) {
    System.out.println("usage: java PrintClient message");
    return;
    * Create a new PrintClient object.
    try {
    client = new PrintClient();
    } catch (BluetoothStateException e) {
    System.out.println("Failed to start Bluetooth System");
    System.out.println("\tBluetoothStateException: " +
    e.getMessage());
    * Find a printer in the local area
    ServiceRecord printerService = client.findPrinter();
    if (printerService != null) {
    * Determine if this service will communicate over RFCOMM or
    * L2CAP by retrieving the connection string.
    String conURL = printerService.getConnectionURL(
    ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
    int index= conURL.indexOf(':');
    String protocol= conURL.substring(0, index);
    if (protocol.equals("btspp")) {
    * Since this printer service uses RFCOMM, create an RFCOMM
    * connection and send the data over RFCOMM.
    RFCOMMPrinterClient printer = new RFCOMMPrinterClient(conURL);
    printer.printJob(args[0]);
    } else if (protocol.equals("btl2cap")) {
    * Since this service uses L2CAP, create an L2CAP
    * connection to the service and send the data to the
    * service over L2CAP.
    L2CAPPrinterClient printer = new L2CAPPrinterClient(conURL);
    printer.printJob(args[0]);
    } else {
    System.out.println("Unsupported Protocol");
    } else {
    System.out.println("No Printer was found");
    * Called when a device was found during an inquiry. An inquiry
    * searches for devices that are discoverable. The same device may
    * be returned multiple times.
    * @see DiscoveryAgent#startInquiry
    * @param btDevice the device that was found during the inquiry
    * @param cod the service classes, major device class, and minor
    * device class of the remote device being returned
    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
    System.out.println("Found device = " + btDevice.getBluetoothAddress());
    * Since service search takes time and we are already forced to
    * complete an inquiry, we will not do a service
    * search on any device that is not an Imaging device.
    * The device class of 0x600 is Imaging as
    * defined in the Bluetooth Assigned Numbers document.
    // if (cod.getMajorDeviceClass() == 0x600) {
    * Imaging devices could be a display, camera, scanner, or
    * printer. If the imaging device is a printer,
    * then bit 7 should be set from its minor device
    * class according to the Bluetooth Assigned
    * Numbers document.
    // if ((cod.getMinorDeviceClass() & 0x80) != 0) {
    * Now we know that it is a printer. Now we will verify that
    * it has a rendering service on it. A rendering service may
    * allow us to print. We will have to do a service search to
    * get more information if a rendering service exists. If this
    * device has a rendering service then bit 18 will be set in
    * the major service classes.
    // if ((cod.getServiceClasses() & 0x40000) != 0) {
    deviceList.addElement(btDevice);
    * The following method is called when a service search is completed or
    * was terminated because of an error. Legal status values
    * include:
    * <code>SERVICE_SEARCH_COMPLETED</code>,
    * <code>SERVICE_SEARCH_TERMINATED</code>,
    * <code>SERVICE_SEARCH_ERROR</code>,
    * <code>SERVICE_SEARCH_DEVICE_NOT_REACHABLE</code>, and
    * <code>SERVICE_SEARCH_NO_RECORDS</code>.
    * @param transID the transaction ID identifying the request which
    * initiated the service search
    * @param respCode the response code which indicates the
    * status of the transaction; guaranteed to be one of the
    * aforementioned only
    public void serviceSearchCompleted(int transID, int respCode) {
    System.out.println("serviceSearchCompleted(" + transID + ", " + respCode + ")");
    * Removes the transaction ID from the transaction table.
    removeFromTransactionTable(transID);
    serviceSearchCount--;
    synchronized (this) {
    this.notifyAll();
    * Called when service(s) are found during a service search.
    * This method provides the array of services that have been found.
    * @param transID the transaction ID of the service search that is
    * posting the result
    * @param service a list of services found during the search request
    * @see DiscoveryAgent#searchServices
    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
    * If this is the first record found, then store this record
    * and cancel the remaining searches.
    if (record == null) {
    System.out.println("FOund a service " + transID);
    System.out.println("Length of array = " + servRecord.length);
    if (servRecord[0] == null) {
    System.out.println("The service record is null");
    record = servRecord[0];
    System.out.println("After this");
    if (record == null) {
    System.out.println("THe Seocnd try was null");
    * Cancel all the service searches that are presently
    * being performed.
    for (int i = 0; i < transactionID.length; i++) {
    if (transactionID[i] != -1) {
    System.out.println(agent.cancelServiceSearch(transactionID[i]));
    * Called when a device discovery transaction is
    * completed. The <code>discType</code> will be
    * <code>INQUIRY_COMPLETED</code> if the device discovery
    * transactions ended normally,
    * <code>INQUIRY_ERROR</code> if the device
    * discovery transaction failed to complete normally,
    * <code>INQUIRY_TERMINATED</code> if the device
    * discovery transaction was canceled by calling
    * <code>DiscoveryAgent.cancelInquiry()</code>.
    * @param discType the type of request that was completed; one of
    * <code>INQUIRY_COMPLETED</code>, <code>INQUIRY_ERROR</code>
    * or <code>INQUIRY_TERMINATED</code>
    public void inquiryCompleted(int discType) {
    synchronized (this) {
    try {
    this.notifyAll();
    } catch (Exception e) {
    * The RFCOMMPrinterClient will make a connection using the connection string
    * provided and send a message to the server to print the data sent.
    class RFCOMMPrinterClient {
    * Keeps the connection string in case the application would like to make
    * multiple connections to a printer.
    private String serverConnectionString;
    * Creates an RFCOMMPrinterClient that will send print jobs to a printer.
    * @param server the connection string used to connect to the server
    RFCOMMPrinterClient(String server) {
    serverConnectionString = server;
    * Sends the data to the printer to print. This method will establish a
    * connection to the server and send the String in bytes to the printer.
    * This method will send the data in the default encoding scheme used by
    * the local virtual machine.
    * @param data the data to send to the printer
    * @return true if the data was printed; false if the data failed to be
    * printed
    public boolean printJob(String data) {
    OutputStream os = null;
    StreamConnection con = null;
    try {
    * Open the connection to the server
    con =(StreamConnection)Connector.open(serverConnectionString);
    * Sends data to remote device
    os = con.openOutputStream();
    os.write(data.getBytes());
    * Close all resources
    os.close();
    con.close();
    } catch (IOException e2) {
    System.out.println("Failed to print data");
    System.out.println("IOException: " + e2.getMessage());
    return false;
    return true;
    * The L2CAPPrinterClient will make a connection using the connection string
    * provided and send a message to the server to print the data sent.
    class L2CAPPrinterClient {
    * Keeps the connection string in case the application would like to make
    * multiple connections to a printer.
    private String serverConnectionString;
    * Creates an L2CAPPrinterClient object that will allow an application to
    * send multiple print jobs to a Bluetooth printer.
    * @param server the connection string used to connect to the server
    L2CAPPrinterClient(String server) {
    serverConnectionString = server;
    * Sends a print job to the server. The print job will print the message
    * provided.
    * @param msg a non-null message to print
    * @return true if the message was printed; false if the message was not
    * printed
    public boolean printJob(String msg) {
    L2CAPConnection con = null;
    byte[] data = null;
    int index = 0;
    byte[] temp = null;
    try {
    * Create a connection to the server
    con = (L2CAPConnection)Connector.open(serverConnectionString);
    * Determine the maximum amount of data I can send to the server.
    int MaxOutBufSize = con.getTransmitMTU();
    temp = new byte[MaxOutBufSize];
    * Send as many packets as are needed to send the data
    data = msg.getBytes();
    while (index < data.length) {
    * Determine if this is the last packet to send or if there
    * will be additional packets
    if ((data.length - index) < MaxOutBufSize) {
    temp = new byte[data.length - index];
    System.arraycopy(data, index, temp, 0, data.length - index);
    } else {
    temp = new byte[MaxOutBufSize];
    System.arraycopy(data, index, temp, 0, MaxOutBufSize);
    con.send(temp);
    index += MaxOutBufSize;
    * Close the connection to the server
    con.close();
    } catch (BluetoothConnectionException e) {
    System.out.println("Failed to print message");
    System.out.println("\tBluetoothConnectionException: " + e.getMessage());
    System.out.println("\tStatus: " + e.getStatus());
    } catch (IOException e) {
    System.out.println("Failed to print message");
    System.out.println("\tIOException: " + e.getMessage());
    return false;
    return true;
    } // End of method printJob.
    } // End of class L2CAPPrinterClient
    SERVER:
    import java.lang.*;
    import java.io.*;
    import javax.microedition.io.*;
    import javax.bluetooth.*;
    * This class will start an RFCOMM service that will accept data and print it
    * to standard out.
    public class RFCOMMPrintServer {
         * This is the main method of the RFCOMM Print Server application.  It will
         * accept connections and print the data received to standard out.
         * @param args the arguments provided to the application on the command
         * line
        public static void main(String[] args) {
            StreamConnectionNotifier server = null;
            String message = "";
            byte[] data = new byte[20];
            int length;
            try {
                LocalDevice local = LocalDevice.getLocalDevice();
                local.setDiscoverable(DiscoveryAgent.GIAC);
            } catch (BluetoothStateException e) {
                System.err.println("Failed to start service");
                System.err.println("BluetoothStateException: " + e.getMessage());
                return;
            try {
                server = (StreamConnectionNotifier)Connector.open(
                    "btspp://localhost:11111111111111111111111111111111");
            } catch (IOException e) {
                System.err.println("Failed to start service");
                System.err.println("IOException: " + e.getMessage());
                return;
            while (!(message.equals("Stop Server"))) {
                message = "";
                StreamConnection conn = null;
                try {
                    try {
                        conn = server.acceptAndOpen();
                    } catch (IOException e) {
                        System.err.println("IOException: " + e.getMessage());
                        return;
                    InputStream in = conn.openInputStream();
                    length = in.read(data);
                    while (length != -1) {
                        message += new String(data, 0, length);
    System.out.println("Message = " + message);
                        try {
                            length = in.read(data);
                        } catch (IOException e) {
                            break;
    System.out.println("Length = " + length);
                    System.out.println(message);
                    in.close();
                } catch (IOException e) {
                    System.out.println("IOException: " + e.getMessage());
                } finally {
                    if (conn != null) {
                        try {
                            conn.close();
                        } catch (IOException e) {
            try {
                server.close();
            } catch (IOException e) {

  • Sharing J2ME & J2SE source with NetBeans

    I will appologize in advance if I am in the wrong forum. However I could not find a forum for NetBeans so here is my problem:
    This problem relates to NetBeans and the J2SE and J2ME Class Libraries. Maybe there is a simple answer to this, but I am unable to figure it out. The JARs are unique enough to where J2ME can not share a J2SE Class Library. I have a few classes that are identical in source between J2SE and J2ME. In NetBeans how can I organize my projects so I do not have to duplicate the source once each for J2SE and J2ME?
    Thank you

    us too. except we're working on a project that requires interfacing a mobile device with a pc. how exactly do we bridge the gap between the two if the device is running j2me and the pc is running j2se?if you have an answer please e-mail us at [email protected]
    thanx

  • XML with J2ME`

    HELLo all,
    i am writing a simple J2ME client for communicating with remote webservices.
    when i wrote a similar client 2 years ago i was using kXML....
    then i went to use other techs for 2 years... now i m back to J2ME and iw as wondering what was the recommened XML api to use on a J2ME device..
    any suggestion?
    thanks and regards
    marco

    forgot to add. cldc does not come with built it
    parser. So you will have to create your own, or
    simply use a 3rd party one.ya ok, thanx... but i hope these 3rd party ones r different from JSR API's... in the sense that it doesnt OEM's to support it or anything.
    and what abt efficiency?
    thanx a ton
    =======
    Kiran

  • Problem parsing xml in J2ME (using kxml2)

    Hello.
    May someone who knows how to use kxml help me please?
    I'll try to be straight forward. (Please excuse my imperfect English)
    My xml file look something like this:
    <?xml version="1.0" encoding="utf-8"?>
    <sample_tag1 xmlns:mysample="http://www.sample001.com/sample01schema">
    <feature name=”tag1_feature”>
         <test name=”xxxxx” id=”200” message=”Hello.”></test>
    </feature>
    <catalog name="shelf">
         <booklist name="book1" label="b1"></booklist>
         <booklist name="book2" label="b2"></booklist>
         <booklist name="book3" label="b3"></booklist>
    </catalog>
    </sample_tag1>
    And here's my code
              //http request
                   try{
                   //I can guarantee that the URL is valid
    httpConnection = (HttpConnection) Connector.open(URL);
    }catch(IOException ioe){
    ioe.printStackTrace();
                   //Create the parser
    KXmlParser parser = new KXmlParser();
    try{
                        //I use this code section to test if the xml file is properly placed in the inputStream.
    char[] tempChar = new char[500];
    isr = new InputStreamReader(httpConnection.openInputStream());
    isr.read(tempChar);
    for(int i=0; i<tempChar.length;i++){
    System.out.print(tempChar);
    //set the xml input
    parser.setInput(isr);
    //skip the "<?xml version="1.0" encoding="utf-8"?>" tag
    parser.nextTag();
    parser.require(XmlPullParser.START_TAG, null, "sample_tag1");
                        System.out.println("name : " + parser.getName());
    System.out.println("namespace : " + parser.getNamespace());
    parser.nextTag(); // ***1
    I compiled the app and run, here's the result:
    name : sample_tag1
    namespace :
    org.xmlpull.v1.XmlPullParserException: attr value delimiter missing! (position:START_TAG <feature name='http://www.sample001.com/sample01schema'>@3:15 in java.io.InputStreamReader@e938beb1)
    at org.kxml2.io.KXmlParser.exception(+47)
    at org.kxml2.io.KXmlParser.error(+45)
    at org.kxml2.io.KXmlParser.parseStartTag(+285)
    at org.kxml2.io.KXmlParser.nextImpl(+314)
    at org.kxml2.io.KXmlParser.next(+23)
    at org.kxml2.io.KXmlParser.nextTag(+24)
    at MyMidlet$ReadXML.run(MyMidlet.java:235)
    But when I comment the last line (parser.nextTag(); // ***1), here's the result:
    name : sample_tag1
    namespace :
    My code is the clone of the one in this tutorial:
    http://www.developer.com/ws/article.php/3759471
    where he get the weather forecast from Yahoo Weather RSS
    What did I do wrong? I tried looking up google for "attr value delimiter missing!" but found no useful information.
    Thank you in advance. =)

    Please read this topic. I posted an answer about parsing xml using kxml2
    http://forums.sun.com/thread.jspa?threadID=5291592&start=0&tstart=0
    Regards,
    David

  • Parsing xml using j2me

    hi
    how can i insert into file xml in midlet for exemple
    <users>
    <user>
    <name>manel<name>
    </user>
    </users>
    it will be
    <users>
    <user>
    <name>manel<name>
    </user>
    <user>
    <name>hajer<name>
    </user>
    </users>
    thx

    You can use kxml for this.
    Regards,
    David.

  • How can remove child into file xml using J2ME

    i want to delete child from file xml using midlet but nothing is changed into file
    please help me
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package ajou;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.util.Vector;
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.midlet.MIDlet;
    import org.kxml2.io.KXmlParser;
    import org.kxml2.kdom.Document;
    import org.kxml2.kdom.Element;
    import org.kxml2.kdom.Node;
    * @author -Manel-
    public class manelGO extends MIDlet {
    public void startApp() {
    try {
              //Open http connection
              HttpConnection httpConnection = (HttpConnection) Connector.open("http://localhost:8080/examples/users.xml");
                   //Initilialize XML parser
                   KXmlParser parser = new KXmlParser();
                   parser.setInput(new InputStreamReader(httpConnection.openInputStream()));
                   Document theDoc = new Document();
                   theDoc.parse(parser);
                   Element rootElement = theDoc.getRootElement();
    rootElement.removeChild(1);
              catch (Exception e) {
                   e.printStackTrace ();
    public void pauseApp() {
    public void destroyApp(boolean unconditional) {
    }

    To achieve this you can use the bpelx:remove function: http://download.oracle.com/docs/cd/E12483_01/integrate.1013/b28981/manipdoc.htm#CIHJBJFD
    your assign will look like:
    <bpel:assign>
    <bpelx:remove>
    <target variable="person" query="/person/@per" />
    </bpelx:remove>
    </bpel:assign>
    Regards,
    Melvin

  • Bluetooth J2ME

    I am to ask that is it always neccessary to make client/server archetecture
    in the communication of bluetooth ...i.e I want to say that i dont want my one device to act as client and other device to act as server. I only want to have communication between two clients ..Is it possible?

    Check out the following site:
    http:// www.benhui.net/bluetooth

  • Parsing Xml in J2me?

    Hye,
    i am using the following block of code in my program. This program when executes, shows an error of END_TAG need to be expected. well, i have defined the tags and i am not getting how to reslove this error....
    Can anyone helps me out???
    void XMLparser ( InputStreamReader reader )throws IOException
         try
              XmlPullParserFactory factory =      XmlPullParserFactory.newInstance(
                                  System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
                   XmlPullParser parser = factory.newPullParser();
                   try
                   {                                                                      factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
                   catch (XmlPullParserException ex)
                   System.err.println("This is not a validating parser");
                   parser.setInput(reader);          
                   int eventType = parser.getEventType();
                   int count = 0;
                   while (eventType != XmlPullParser.END_DOCUMENT)
                        if(eventType == XmlPullParser.START_DOCUMENT)
                             textField.setString("Searched: "+word);
                             System.out.println(word);
                        else if(eventType == XmlPullParser.END_DOCUMENT)
                             System.out.println("End Doc");
                        else if(eventType == XmlPullParser.START_TAG)
                             if(parser.getName().equals("dictionary"))
                                  String string = parser.nextText();
                                  System.out.println("Dictionary");
                             else if(parser.getName().equals("meanings"))
                                  String string = parser.nextText();     
                                  System.out.println("Meanings");
         (parser.getName().equals("meaning"));                         {
                                  String string = parser.nextText();
                        else if(eventType == XmlPullParser.END_TAG)
                        System.out.println("End Tag");
                        else if(eventType == XmlPullParser.TEXT)
                             System.out.println("Meanings!!");
                        eventType = parser.next();
                   }// while close     
         }// try close
         catch (XmlPullParserException ex)
              ex.printStackTrace();
         }// XMLparser() close

    Hye,
    i am using the following block of code in my program. This program when executes, shows an error of END_TAG need to be expected. well, i have defined the tags and i am not getting how to reslove this error....
    Can anyone helps me out???
    void XMLparser ( InputStreamReader reader )throws IOException
         try
              XmlPullParserFactory factory =      XmlPullParserFactory.newInstance(
                                  System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
                   XmlPullParser parser = factory.newPullParser();
                   try
                   {                                                                      factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
                   catch (XmlPullParserException ex)
                   System.err.println("This is not a validating parser");
                   parser.setInput(reader);          
                   int eventType = parser.getEventType();
                   int count = 0;
                   while (eventType != XmlPullParser.END_DOCUMENT)
                        if(eventType == XmlPullParser.START_DOCUMENT)
                             textField.setString("Searched: "+word);
                             System.out.println(word);
                        else if(eventType == XmlPullParser.END_DOCUMENT)
                             System.out.println("End Doc");
                        else if(eventType == XmlPullParser.START_TAG)
                             if(parser.getName().equals("dictionary"))
                                  String string = parser.nextText();
                                  System.out.println("Dictionary");
                             else if(parser.getName().equals("meanings"))
                                  String string = parser.nextText();     
                                  System.out.println("Meanings");
         (parser.getName().equals("meaning"));                         {
                                  String string = parser.nextText();
                        else if(eventType == XmlPullParser.END_TAG)
                        System.out.println("End Tag");
                        else if(eventType == XmlPullParser.TEXT)
                             System.out.println("Meanings!!");
                        eventType = parser.next();
                   }// while close     
         }// try close
         catch (XmlPullParserException ex)
              ex.printStackTrace();
         }// XMLparser() close

  • J2SE Bluetooth API

    Hello,
    I�m working on a project where I have to build a bluetooth server to connect Mobiles to it.
    The problem I have is to find an API to use bluetooth under J2SE. It seems to be easy to find that for J2ME, but not for J2SE.
    I found something on benhui.net, but I�m not sure if this is the best solution.
    Does someone have experiences with something like that?
    I would be very happy to have an API for Win AND Linux. I think I will try the solution from benhui.net, but perhaps someone has a better idea.
    And what about a Linux API? I found that JBluez at sourceforge, but this project seems to be dead (nothing happened there for about 2 years).

    You can map the BT to a COM port on your machine using an adapter software (usually comes with the BT package) and then use APIs that uses the Java COMM API to connect to mobiles that are already connected to the machine via this adapter. such APIs like JSMS authored by http://www.objectxp.com/
    this is not the propper place to post this question, since there is a froums related to the wireless fields at http://forums.java.sun.com/wireless
    GoodLuck
    Regards,
    Mohammed Saleem

  • Question about j2me bluetooth lack of documentation!

    I don't know if I am searching in the wrong places. I am coding a simple (at least for now) java application that communicates through bluetooth.
    I have been using the j2me api available at http://java.sun.com/javame/reference/apis/jsr082/
    But it lacks all sort of information! The API is there... the class and methods are there but nothing is explained....
    For example, if you follow the link above to the api, then click in the DiscoveryAgent, then go to the definition of the method searchServices, this is what it tells you:
    public int searchServices(int[] attrSet, UUID[] uuidSet, RemoteDevice btDev, DiscoveryListener discListener) throws BluetoothStateException
    I can see the declaration, I even deduce what each argument is supposed to be, but..... attrSet???? what is this.... there is a complete lack of information on everything, I find myself googling for everything and finding magic numbers that sometimes make things work. Is there any online resources for bluetooth j2me programming?
    By the way... this thing about the attrSet is my latest doubt... if you know what values can be used in there please let me know:)
    But my problem is not about this particular method... is about all of the documentation.
    If anyone can point me into some place where a good specification can be found i would much appreciate it

    http://www.jcp.org/aboutJava/communityprocess/final/jsr082/
    found this :) I think it's the answer to my problems.

  • How to parse xml file in midlet

    Hi Guys,
    i wish to parse xml file and display it in my midlet. i found api's supporting xml parsing in j2se ie., in java.net or j2se 5.0. Can u please help me what package to use in midlet?
    how to parse xml info and display in midlet? Plz reply soon......Thanks in advance....

    i have exactly the same problem with KXml2, but using a j2me-polish netbeans project.
    i've tried to work around with similar ways like you, but none of them worked. now i've spent 3 days for solving this problem, i'm a bit disappointed :( what is wrong with setting the downloaded kxml2 jar path in libraries&resources?
    screenshot

  • Bluetooth in Windows Mobile

    Ok
    so I am writing a MIDlet that requires access to Bluetooth. The 2 test phones I am using (T-Mobile MDA Vario and MDA III) are both runing Windows Mobile 5.0 OS 5.1.195.
    The problem is: when I emulate the program in the computer, everything works fine. But when I install it on the phones, it seems it does not have access to the bluetooth as it does not show the BT address and friendly name. I already tried another phone (Sony Ericson k 750i) and it worked fine.
    Does anyone know what the problem might be?
    The code I wrote follows:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.bluetooth.*;
    public class BluetoothMidlet extends MIDlet implements CommandListener {
    private Command exit, next, back;
    LocalDevice local;
    Alert a;
    Form startScreen;
    public BluetoothMidlet() {
    exit = new Command("Exit",Command.EXIT, 0);
    next = new Command("Next", Command.SCREEN, 1);
    back = new Command("Back", Command.BACK, 1);
    a = new Alert("Local Device");
    a.addCommand(back);
    a.setTimeout(Alert.FOREVER);
    a.setCommandListener(this);
    startScreen = new Form("Start");
    startScreen.append("Press 'Next' to proceed or 'Exit' to make like a tree");
    startScreen.addCommand(next);
    startScreen.addCommand(exit);
    startScreen.setCommandListener(this);
    public void startApp() {
         show();
    public void pauseApp() {}
    public void destroyApp(boolean unconditional) {}
    public void commandAction(Command c,Displayable d) {
         if(c == next) {
              start();
         if(c == back) {
              show();
    if(c == exit) {
    notifyDestroyed();
    destroyApp(true);
    void show() {
         Display.getDisplay(this).setCurrent(startScreen);
    void start() {
    try {
    // Retrieve the local Bluetooth device object
    local = LocalDevice.getLocalDevice();
    // Retrieve the Bluetooth address of the local device
    String address = local.getBluetoothAddress();
    // Retrieve the name of the local Bluetooth device
    String name = local.getFriendlyName();
    System.out.println(address + name);
    a.setString("Address is "+address+", Name is "+name);
    Display.getDisplay(this).setCurrent(a);
    } catch(Exception e) {
    a.setString(e.getMessage());
    Display.getDisplay(this).setCurrent(a);
    Waiting for answers...

    The problem is that they are not phones (like SE K750i or my K800i) but smartphones, that run Windows Mobile 5. In order to be able to use bluetooth from within Java (on WM5) you need to get [most likely: purchase...] a bluetooth stack implementation which is compatible to WM5 and your Java-Version on your smartphone.
    You could also get trial licences (e.g. from here: http://www.avetana-gmbh.de/avetana-gmbh/produkte/jsr82.eng.xml ). Avetana (for example) you can use in combination with IBM's J9 or NSICOM's Cre-Me and WM2003 or WM5. I am currently writing my thesis about bluetooth & j2me and need to write a client/server-app using those technologies. I'd like to try to run the midlet on my PDA (WM5 + J9), too, but as I couldn't find working/good and free bluetooth stack implementations for this platform... I kinda gave up :-P
    More focusing on development with my k800i right now. When my thesis is done I still have time to investigate the PDA-thing.
    Wish you good luck & motivation for your work with your smartphones ;)

  • How to work with xml in java ?

    Hello everybody. I am trying to read, write and modify xml file in java. But i don't know what is the best method for work with xml file ? Please give me some examples for read, write and modify it.
    Thanks in advance.

    >
    Hello everybody. I am trying to read, write and modify xml file in java. But i don't know what is the best method for work with xml file ?>'It depends'. I saw some discussions of XML parsing using different J2SE core XML APIs (the J2SE has a selection of ways to deal with XML) where one API was 20 times faster than the other.
    >
    ... Please give me some examples for read, write and modify it. >Please give me a ponie. ;-)
    You will probably need to do a lot of reading, as well as some experimentation, before you decide which XML API is best suited to the particular task you are facing.
    >
    Thanks in advance.>No worries.

  • J2SE content conversion

    Hi Gurus!
    I have a problem creating XML in J2SE adapter.
    This is the XML I need to get:
    <RECORDSET>
         <ROW>
              <storenum>628</storenum>
              <Storename></Storename>
              <POnumber>00010300</POnumber>
              <POexternal>C8Y17531</POexternal>
              <MaterialNum>497990</MaterialNum>
              <Quantity>00008</Quantity>
              <POdate>20080314</POdate>
              <DeliveryDate>20080317</DeliveryDate>
              <DeliveryID>D8Y19983</DeliveryID>
              <VendorID>231125</VendorID>
              <linenum>1</linenum>
         </ROW>
         <ROW>
              <storenum>390</storenum>
              <Storename></Storename>
              <POnumber>00011267</POnumber>
              <POexternal>C8Y17704</POexternal>
              <MaterialNum>497990</MaterialNum>
              <Quantity>00008</Quantity>
              <POdate>20080316</POdate>
              <DeliveryDate>20080317</DeliveryDate>
              <DeliveryID>D8Y20036</DeliveryID>
              <VendorID>231125</VendorID>
              <linenum>1</linenum>
         </ROW>
    </RECORDSET>
    And this, is what I get now:
    <RECORDSET>
         <ROW>
              <storenum>628</storenum>
              <Storename></Storename>
              <POnumber>00010300</POnumber>
              <POexternal>C8Y17531</POexternal>
              <MaterialNum>497990</MaterialNum>
              <Quantity>00008</Quantity>
              <POdate>20080314</POdate>
              <DeliveryDate>20080317</DeliveryDate>
              <DeliveryID>D8Y19983</DeliveryID>
              <VendorID>231125</VendorID>
              <linenum>1</linenum>
         </ROW>
    </RECORDSET>
    <RECORDSET>
         <ROW>
              <storenum>390</storenum>
              <Storename></Storename>
              <POnumber>00011267</POnumber>
              <POexternal>C8Y17704</POexternal>
              <MaterialNum>497990</MaterialNum>
              <Quantity>00008</Quantity>
              <POdate>20080316</POdate>
              <DeliveryDate>20080317</DeliveryDate>
              <DeliveryID>D8Y20036</DeliveryID>
              <VendorID>231125</VendorID>
              <linenum>1</linenum>
         </ROW>
    </RECORDSET>
    Here is my code:
    ##CONTENT CONVERSION paramters
    xml.recordsetName=RECORDSET
    xml.recordsetsPerMessage=*
    xml.processFieldNames=fromConfiguration
    xml.keyFieldType=Float
    xml.keyFieldName=ROW
    xml.recordsetStructure=ROW,1
    #xml.fieldNames=storenum,Storename,POnumber,POexternal,MaterialNum,Quantity,POdate,DeliveryDate,DeliveryID,VendorID,linenum
    #xml.fieldFixedLengths=6,20,8,10,13,5,8,8,10,10,13
    xml.documentName=DeliveryNotes...
    xml.documentNamespace=http://...
    xml.ROW.fieldFixedLengths=6,20,8,10,13,5,8,8,10,10,13
    xml.ROW.keyFieldValue=1
    xml.ROW.fieldNames=storenum,Storename,POnumber,POexternal,MaterialNum,Quantity,POdate,DeliveryDate,DeliveryID,VendorID,linenum
    What is my problem?

    Thanks Gabriel.
    If I change to xml.recordsetStructure=ROW,*
    J2SE is not running, in LOG there are these messages
    14:38:39 (4023): File adapter initialized successfully
    14:38:39 (4007): File adapter started
    14:38:39 (4051): Process 1 file(s):
    14:38:39 : D:\Temp\Plainj2seTest\Movil\PDN1403778.txt
    14:38:39 (4052): Start processing "TXT" file "D:\Temp\Plainj2seTest\Movil\PDN1403778.txt" size 1130 in "EO mode
    14:38:39 (4058): Start converting to XML format 
    14:38:39 (4061): Converted complete file content to XML format 
    14:38:39 (4078): Empty document found. Skip and proceed with next message
    14:38:39 (4037): File "PDN1403778.txt" processed successfully

Maybe you are looking for

  • Can't save new address from Mail.app

    Hi. I forget the name of the service, but when an address shows up in a Mail message you can select it and get a pop-up to add or update a contact in Address Book. It doesn't work when I try to do that. This error shows up in the log: 1/8/10 8:27:06

  • "not enough free space" msg appearing incorrectly. Unable to properly sync.

    I have been searching through the posts and haven't seen one similar to this: Initially, my nano worked wonderfully. Then, around Thanksgiving, anytime I tried to sync it with my laptop, I received an error stating it was too full to sync -- even if

  • Recovery Disc & new ProBook 4530s

    How do I create a recovery disc for a new ProBook 4530s with Windows 7?  I can't find Recovery Manager software on the pc and the pc didn't ask me if I wanted to create a recovery disc.

  • Illustrator not able to round corners properly (w/ image sample)

    When designing a logo, I want to be able to round corners properly, i.e. mathematically. When I specify a radius of 20 mm, I expect a radius of 20 mm, not various random radiuses. Illustrator simply isn't capable of doing this properly. I find this v

  • AR and AP upload -T Code F-02.

    Hi Team, Let me know correct approach BDC or BAPI or LSMW for AR AP upload - T Code F-02. Thanks MMV