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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:57:16+00:00 2026-06-10T10:57:16+00:00

I want to parse the xml file to get the root element. Then append

  • 0

I want to parse the xml file to get the root element. Then append add the tag named first-name under that root tag. How do I do this ? This is what I have been doing right now :

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();            
        Document document = db.newDocument();

        Element blobKey_E = document.createElement("first-name");
        blobKey_E.appendChild( document.createTextNode( name ) );
        // NOW APPEND blobKey_E to the root element 
        // After getting the root element from the xml in some directory

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(new File("/home/non-admin/NetBeansProjects/Personal Site_Testers/web/xml/xml_1.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-06-10T10:57:18+00:00Added an answer on June 10, 2026 at 10:57 am
    Element root = document.getDocumentElement();
    root.appendChild(document.createElement("first-name"));
    

    Will append first-name to the end of the DOM tree

    Inserting into the first position is a little more difficult…

    Element root = document.getDocumentElement();
    if (root.hasChildNodes()) {
        Node firstChild = root.getFirstChild();
        root.insertBefore(document.createElement("first-name"), firstChild);
    } else {
        // Append to as per previous example
    }
    

    UPDATE

    Eleement firstName = document.createElement("first-name");
    firstName.setTextContent("Henry");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using XML::Simple to parse an XML file which I then want to use
I want to parse an XML file, consisting, among others: <xml> <t> <name>object</name> <t1
I am using GWT and want to parse an xml file, but I get
I am having one xml file and I want to parse it to get
I want to parse xml file in utf-8 and sort it by some field.
I want to parse the xml file with dynamic content using DOM parser in
I want to parse a xml file using xquery in Ruby, I found this
I want to parse a large XML file and I have two options: Perl
I have an XML file and parse it into my PHP document. I want
I want to parse xml files that have elements like these: <element>&amp</element> <element>&amp;</element> But

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.