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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:30:15+00:00 2026-05-23T12:30:15+00:00

I would like to write some content to a XML file. For that I

  • 0

I would like to write some content to a XML file. For that I have created a XML file and writen tags with element, attribute and value with some data like this:

XmlSerializer serializer = Xml.newSerializer();
serializer.startTag(null, element);
serializer.attribute(null, atbname, value);
serializer.text(text);
serializer.endTag(null, tag);

If I want to add a new tag with new elements, new attributes, etc. and I enter the element at the place of tag it is modifying with previous the tag.

How can I append the new tag to the previously appended tags?

  • 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-23T12:30:15+00:00Added an answer on May 23, 2026 at 12:30 pm

    Take a look at this link. It should give you an idea of how to add nodes to your XML. Here is a snippet.

    public DomXmlExample() {
            try {
                /////////////////////////////
                //Creating an empty XML Document
    
                //We need a Document
                DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
                Document doc = docBuilder.newDocument();
    
                ////////////////////////
                //Creating the XML tree
    
                //create the root element and add it to the document
                Element root = doc.createElement("root");
                doc.appendChild(root);
    
                //create a comment and put it in the root element
                Comment comment = doc.createComment("Just a thought");
                root.appendChild(comment);
    
                //create child element, add an attribute, and add to root
                Element child = doc.createElement("child");
                child.setAttribute("name", "value");
                root.appendChild(child);
    
                //add a text element to the child
                Text text = doc.createTextNode("Filler, ... I could have had a foo!");
                child.appendChild(text);
    
                /////////////////
                //Output the XML
    
                //set up a transformer
                TransformerFactory transfac = TransformerFactory.newInstance();
                Transformer trans = transfac.newTransformer();
                trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                trans.setOutputProperty(OutputKeys.INDENT, "yes");
    
                //create string from xml tree
                StringWriter sw = new StringWriter();
                StreamResult result = new StreamResult(sw);
                DOMSource source = new DOMSource(doc);
                trans.transform(source, result);
                String xmlString = sw.toString();
    
                //print xml
                System.out.println("Here's the xml:\n\n" + xmlString);
    
            } 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

I'd like to write a function that would have some optional code to be
I have some xml that looks like this: <rootElement attribute=' > '/> This is
I would like to write some data to a file in Ruby. What is
I would like to write some scripts in python that do some automated changes
I have a quad core machine and would like to write some code to
I would like to write a command line tool that passes some formatted text
I'm trying to write some LINQ To SQL code that would generate SQL like
I would like to have some functionality by which if I write <textarea maxlength=50></textarea>
I would like to write some Objective-C code for distribution. What is the best
I would like to write an simple application able to retrieve some certain data

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.