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

  • Home
  • SEARCH
  • 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 8366461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:55:30+00:00 2026-06-09T12:55:30+00:00

Friends I want to create a xml file in my android app where I

  • 0

Friends I want to create a xml file in my android app where I want to store a variable for image(later on I would fetch that image from resources),date,time & number. All these things would be cuimg at run time. So I am finding it difficult to save them in form of xml file.Also I wish to read info from this fila back again. Please help me with the same.

Friends I got solution from http://www.anddev.org/write_a_simple_xml_file_in_the_sd_card_using_xmlserializer-t8350.html but now I am facing the issue is that only the latest values are over written with the last values(I have tested it by using date feature)
Please help me for the same

  • 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-06-09T12:55:32+00:00Added an answer on June 9, 2026 at 12:55 pm

    You may use DOM or SAX API to create and parse the XML document.

    DOM sample to create XML document:

     DocumentBuilderFactory factory=null;
     DocumentBuilder builder=null;
     try {
        //1
        factory=DocumentBuilderFactory.newInstance();
        builder=factory.newDocumentBuilder();
    
        //2
        Document document=builder.newDocument();
    
        //3
        document.setXmlVersion("1.0");
    
        //4
        Node root=document.createElement("Students");
    
    
        Element student=document.createElement("Student");
        student.setAttribute("class", "1");
        Element roll=document.createElement("Roll");
        Element name=document.createElement("Name");
    
        roll.appendChild(document.createTextNode("10"));
        name.appendChild(document.createTextNode("Mr.X"));
    
        student.appendChild(roll);
        student.appendChild(name);
    
        root.appendChild(student);
    
        document.appendChild(root);
    
           //5
        TransformerFactory transFactory=TransformerFactory.newInstance();
        Transformer trans=transFactory.newTransformer();
    
        trans.setOutputProperty(OutputKeys.INDENT, "yes");
        trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "5");
    
        trans.transform(new DOMSource(document),new StreamResult("file.xml"));
    
        } catch (Exception e) {
          System.out.println(e);
        }
    

    To read/parse XML document:

    DocumentBuilderFactory factory=null;
       DocumentBuilder builder=null;
       Document doc=null;
    
       try {
        factory=DocumentBuilderFactory.newInstance();
        builder=factory.newDocumentBuilder();
    
        doc=builder.parse("file.xml");
    
        Element  root=doc.getDocumentElement(); //root
    
        NodeList list=root.getChildNodes();
    
        for(int i=0;i<list.getLength();i++){
        Node node=list.item(i);
        switch(node.getNodeType()){
            case Node.TEXT_NODE:
                      System.out.println("Text Node"); break;
            case Node.ELEMENT_NODE:
                case Node.ATTRIBUTE_NODE:
                      System.out.println("Element Node");
                      NodeList student=node.getChildNodes();
                      if(node.hasAttributes()){
                          System.out.println(node.getAttributes()
                                     .getNamedItem("class").getTextContent());
                  }
                 for(int j=0;j<student.getLength();j++){
                      Node nd=student.item(j);
                              if(nd.getNodeType()==Node.ELEMENT_NODE){
                                System.out.println(nd.getNodeName() + " " 
                                             + nd.getTextContent());
                                }
                 }
                 break;
            default:
                  System.out.println("Other node");
                  break;
               }
             }
        } catch (Exception e) {
             System.out.println(e);
          } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi friends i have an ajax()of jquery that parse the xml file , create
I want to create a friends system like facebook, well quite weird than that.
I want to create something like the Find my Friends app, in terms of
Hi friends i want to create a view in that I can add texts
Ultimately I want to create a desktop app that allows users to update their
I want to create an application where I'll create an image from the application
I want to create gif/png image file using java programatically. This gif/png image should
I want to create an app that shows text, plays sound (mp3 files) and
I want to create a table of friends with personal information and log on
I often want to send sample apps to friends & colleages that work with

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.