Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 213471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:16:54+00:00 2026-05-11T18:16:54+00:00

I have created XML file,but I can’t view it/output it.I know there is no

  • 0

I have created XML file,but I can’t view it/output it.I know there is no way to output created XML file.

Can anyone please suggest what is better way of creating xml files?
1. create xml with DocumentBuilderFactory and then parse it Or
2. manually create hardcoded xml and save it on sd card and then access it for parsing.

I have continuosly varying text data in xml files.
Which approach will suite me most?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:16:54+00:00Added an answer on May 11, 2026 at 6:16 pm

    I’m using kXML2 to create/chage/save/read xml. Using it with BlackBerry remember:
    – for release you have to preverify it & build proj with ant
    Ahmad Ferdous Bin Alam – How to Import kxml jar File to Your Project
    Slashdev – BlackBerry Development with Ant & Eclipse
    UPDATE: Tutorial: How To Use 3rd Party Libraries in your Applications
    – for debug you have to add kXML sources and org.xmlpull.v1 sources to your BB project

    Create XML

        Document d = new Document();
        Element root = d.createElement("", "parent");       
        root.setName("catalog");
        Element book = d.createElement("", "child");            
        book.setName("book");       
        book.setAttribute(null, "id", "1");             
        Element author = d.createElement("", "child");              
        author.setName("author");               
        author.addChild(0, Node.TEXT, "Colin Wilson");      
        book.addChild(0, Node.ELEMENT, author);
    
        Element title = d.createElement("", "child");           
        title.setName("title");             
        title.addChild(0, Node.TEXT, "The Mind Parasites");     
        book.addChild(1, Node.ELEMENT, title);
    
        Element genre = d.createElement("", "child");           
        genre.setName("genre");
        genre.addChild(0, Node.TEXT, "Horror novel, Science fiction novel");    
        book.addChild(2, Node.ELEMENT, genre);
    
        Element publishDate = d.createElement("", "child");             
        publishDate.setName("publish-date");                
        publishDate.addChild(0, Node.TEXT, "1967"); 
        book.addChild(3, Node.ELEMENT, publishDate);
    
        root.addChild(0, Node.ELEMENT, book);
        d.addChild(root.ELEMENT, root);
    

    Save XML on BlackBerry filesystem

    • If use emulator don’t forget to emulate SD card (Tools->Change SD Card…)
    • be sure you have access rights for read/write operation

      String fileName = "file:///SDCard/books.xml";
      DataOutputStream os = null;
      FileConnection fc = null;
      try {
          fc = (FileConnection) Connector.open(fileName, Connector.READ_WRITE);
          if (!fc.exists())
              fc.create();
      
          os = fconn.openDataOutputStream();
          KXmlSerializer serializer = new KXmlSerializer();
          serializer.setOutput(os, "UTF-8");
          d.write(serializer);
      
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } 
      

      See also:
      RIM API – Interface FileConnection
      SUN Dev Network – Getting Started with the FileConnection APIs
      RIM – How To – Add plain text or binary files to an application
      BB Support Forum – Some questions about FileConnection/JSR 75
      Sony Ericsson Forum – Create XML file

    Read XML file

        Document d= new Document();
        FileConnection fc =  null;
        DataInputStream is = null;
        try {
            fc = (FileConnection) Connector.open(fileName, Connector.READ);
            is = fc.openDataInputStream();
    
            KXmlParser parser = new KXmlParser();
            parser.setInput(is, "UTF-8");
            d.parse(parser);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    

    See also:
    RoseIndia.net – J2ME Kxml Example

    Change XML document

    All you have to do is get needed element and change it:

        Element catalog = d.getElement("", "catalog");
    
        Element book = catalog.getElement("", "book");
    
        Element title = book.getElement("", "title");
        title.removeChild(0);
        title.addChild(Element.TEXT, "Spider World: The Tower");
    
        Element publish = book.getElement("", "publish-date");
        publish.removeChild(0);
        publish.addChild(Element.TEXT, "1987");
    

    Output XML document to BlackBerry screen (somewhere in Screen class)

    Simply serialize xml doc to string and put it in RichTextField:

        deleteAll();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();       
        KXmlSerializer serializer = new KXmlSerializer();
        try {
            serializer.setOutput(baos, "UTF-8");
            d.write(serializer);    
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   
        add(new RichTextField(baos.toString()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a layout.xml file with the following XML, but I can't get the
I have created an XML file and DTD which can be found at the
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have created the following vsct file xml. <?xml version=1.0 encoding=utf-8?> <CommandTable xmlns=http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable xmlns:xs=http://www.w3.org/2001/XMLSchema>
When I have an Eclipse update site project, a site.xml file is created which
I have an XML document as follows: <directory> <file><monitored>0</monitored> <xferStatus>1</xferStatus> <name>test1.txt</name> <size>7</size> <created>03/31/10 11:30:02
I have been thinking about the optimal way to create an XML file using
I have created a service that updates dictionaries and outputs an xml file of
I have .MAP file which is created from SAS XML mapper. As the name
How can I have a text file (or XML file) represented as a whole

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.