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 6109087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:21:57+00:00 2026-05-23T14:21:57+00:00

i would like to append a new tag with some attributes with those values

  • 0

i would like to append a new tag with some attributes with those values in to xml file and save that xml file through my application.i have written a method for append a new tag as child to xml file which is available in sdcard of android emulator.the following method for append a new tag as follows

   public void appendTag(){

    try{

        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        Document doc = docBuilder.parse (new File("/sdcard/sample.xml"));

     Node node = doc.getElementsByTagName("earth").item(0);

     //append a new node to earth
     Element newelmnt = doc.createElement("new");
     newelmnt.appendChild(doc.createTextNode("this is a text"));
     node.appendChild(newelmnt);


    }
    catch (Exception e) {
        e.printStackTrace();
    }

}

after execution of this method i can’t able to find a new tag in xml file.

could please any one help on how to append new tag as child in xml file and how save the modification?

if i uses TransformerFactory i am getting error as
ERROR/AndroidRuntime(13479): java.lang.VerifyError: com.sample.xmlapp.DOMClass
i have used as follows

     TransformerFactory factory = TransformerFactory.newInstance();
     Transformer transformer = factory.newTransformer();

     DOMSource source = new DOMSource(doc);
     StreamResult result = new StreamResult(new File("/sdcard/sample.xml"));
     transformer.transform(source, result);
  • 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-23T14:21:57+00:00Added an answer on May 23, 2026 at 2:21 pm

    Your in memory document will be changed, but you will need to write it to a file again.

    Try adding this for writing the document to the file again:

    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(new File("/sdcard/sample.xml"));
    transformer.transform(source, result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing XML file that I would like to append without changing
I would like to write some content to a XML file. For that I
I would like to append a new line to an existing file without erasing
I am new to using jquery and would like to know how to append
I would like to implement a functionality that insert a word-breaking TAG if a
I am new to QT and I am doing some learning. I would like
I have an XML document that I would like to update after it already
I have a <td> that currently has some content in it. I would like
I would like to append a byte array to an already existing file (C:\test.exe)
I would like to include the encoding tag in an XML document using BeautifulSoup.BeautifulStoneSoup

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.