×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    15

    How to create xml file by J2ME ?

    hi

    i am a beginer in j2me

    i need to create an xml file
    in j2me (on N6288)

    can any one help my pls whit code for that ?

    tanks

  2. #2
    Registered User
    Join Date
    Oct 2007
    Location
    Paris
    Posts
    32

    Thumbs up Re: How to create xml file by J2ME ?

    hi this is mayur,

    The concept of generating xml file if same in java. if you wanna use j2me you should do file handling in your code.

    Below is code written in jsp, the only thing you need to modify is to replace the file writing command.

    int iLf = 10;
    char cLf = (char)iLf;
    String xmlfile="path to your directroy/Data.xml";
    File outputFile = new File(xmlfile);
    outputFile.createNewFile();
    FileWriter outfile = new FileWriter(outputFile);

    outfile.write("<?xml version='1.0' encoding='ISO-8859-1'?>"+cLf);

    outfile.write("<Table>"+cLf);
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * from users");



    while(rs.next())
    {

    outfile.write("<users>"+cLf);
    outfile.write("<cid>" + rs.getString(1) +"</cid>"+cLf);
    outfile.write("<cname>" + rs.getString(2) +"</cname>"+cLf);
    outfile.write("<username>" + rs.getString(3) +"</username>"+cLf);
    outfile.write("<password>" + rs.getString(4) +"</password>"+cLf);
    outfile.write("<email>" + rs.getString(5) +"</email>"+cLf);
    outfile.write("<cellno>" + rs.getString(6) +"</cellno>"+cLf);
    outfile.write("<address>" + rs.getString(7) +"</address>"+cLf);
    outfile.write("<city>" + rs.getString(8) +"</city>"+cLf);
    outfile.write("<state>" + rs.getString(9) +"</state>"+cLf);
    outfile.write("<zip>" + rs.getString(10) +"</zip>"+cLf);
    outfile.write("<country>" + rs.getString(11) +"</country>"+cLf);
    outfile.write("<question>" + rs.getString(12) +"</question>"+cLf);
    outfile.write("<answer>" + rs.getString(13) +"</answer>"+cLf);
    outfile.write("</users>"+cLf);
    Mayur Dharukiya
    M.B.A+B.E.+Diploma In Information Technology + SAP HR Consultant
    Tata Consultancy Services Certified Java Developer
    Brainbench Ceftified Java Developer Transcript ID is 6577305
    htttp://www.ampleassociation.com

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    15

    Re: How to create xml file by J2ME ?

    is that so ?

    i understod i need to use an api to do write new file in j2me

    what api do i need

    a link for download for NOKIA 6288

    will be wonderful

    thanks

  4. #4
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    88

    Re: How to create xml file by J2ME ?

    Hi,
    there are many api for XML parsing available for J2ME environment - NanoXML, KXML, etc. With NanoXML, you can do this:

    Code:
    kXMLElement element = new kXMLElement();
    element.setTagName("root");
    element.addProperty("key", "value");
    
    kXMLElement child = new kXMLElement();
    child.setTagName("child");
    child.setContent("Teste");
    element.addChild(child);
    
    kXMLElement child2 = new kXMLElement();
    child2.setTagName("child");
    child2.setContent("conteudo");
    child2.addProperty("propriedade", "valoer");
    element.addChild(child2);
    You will have:

    Code:
    <root KEY="value">
        <child>Teste</child>
        <child PROPRIEDADE="valoer">conteudo</child>
    </root>
    Simple, doen't it?

    []'s

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    15

    Re: How to create xml file by J2ME ?

    thanks !!!

    how do i save the element to be an XML file ?

    i understand that it is element.write

    but wat it the writer and how do i give him the file name

    he takes java.io has parameter
    Last edited by aaaabaaaa; 2008-10-30 at 11:30.

  6. #6
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Tel-Aviv,Israel
    Posts
    100

    Lightbulb Re: How to create xml file by J2ME ?

    Y

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    15

    Re: How to create xml file by J2ME ?

    thanks but

    that exsamel is for using an existing XML

    i am trying to creat a new simpel XML file on my NOKIA 6288

    by j2me

    i have a problem in saving the

    kNanoXML.kXMLElement element = new kNanoXML.kXMLElement();
    element.setTagName("root");
    element.addProperty("key", "value");

    kNanoXML.kXMLElement child = new kNanoXML.kXMLElement();
    child.setTagName("child");
    child.setContent("Teste");
    element.addChild(child);

    kNanoXML.kXMLElement child2 = new kNanoXML.kXMLElement();
    child2.setTagName("child");
    child2.setContent("conteudo");
    child2.addProperty("propriedade", "valoer");
    element.addChild(child2);

    the "element " to XML file

    Writer writer=null ;
    try
    {
    writer.write("c:\\aa.xml");
    element.write(writer) ;
    }
    catch (Exception e)
    {
    System.out.println("problem in writeing XML file ----- " + e.toString());
    }

    nonworking
    it run but ther is not a new file...

  8. #8
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Tel-Aviv,Israel
    Posts
    100

    Lightbulb Re: How to create xml file by J2ME ?

    Hi
    You need to Use File Connection API in J2Me to work with Files.
    simple example to write files in J2me
    Code:
    try 
    {
      FileConnection fconn = (FileConnection)Connector.open("file:///CFCard/newfile.txt");
      if (!fconn.exists())
        fconn.create();  // create the file if it doesn't exist
      fconn.close();
    }
    catch (IOException ioe) 
    {
    Y

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    15

    Re: How to create xml file by J2ME ?

    so how i conect that to the kNanoXML

  10. #10
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Tel-Aviv,Israel
    Posts
    100

    Re: How to create xml file by J2ME ?

    Lets starts again mate...
    Explain Properly your desired Wish.

    Tip : use Bullets Points to Highlight each stage in your development.
    Y

  11. #11
    Registered User
    Join Date
    Oct 2008
    Posts
    15

    Re: How to create xml file by J2ME ?

    I want to crate a simpel XML file by j2me on my mobile N6288

    after that i will want to send it over bluetooth to my PC

  12. #12
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Tel-Aviv,Israel
    Posts
    100

    Lightbulb Re: How to create xml file by J2ME ?

    Ok,

    1) http://www.devx.com/xml/Article/11773/0/page/1

    2) Use RMS to store the XML( No Need to save the File over SD)

    BT:
    3) http://discussion.forum.nokia.com/fo...d.php?t=148525

    Good Luck
    Y

Similar Threads

  1. Trusted Application
    By damien_a in forum Mobile Java General
    Replies: 11
    Last Post: 2012-02-17, 20:49
  2. Problem with GCCE build in Carbide.vs
    By raffaelbechara in forum Symbian
    Replies: 6
    Last Post: 2008-10-20, 16:06
  3. Sending XML file from server to mobile
    By bvsbh in forum Mobile Java General
    Replies: 1
    Last Post: 2005-11-30, 14:21
  4. Replies: 1
    Last Post: 2005-05-26, 14:22
  5. Replies: 0
    Last Post: 2002-06-10, 12:24

Posting Permissions

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