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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:56:44+00:00 2026-06-10T00:56:44+00:00

So I am using the DOM parser in JAVA to create an XML file.

  • 0

So I am using the DOM parser in JAVA to create an XML file.
When I want to add a child element it ends up looking like this:

<childElement attribute1="attributeValue" attribute2="attributeValue"/>

However I would rather that my XML look like this (though obviously DOM won’t make these indentations and seperate lines):

<childElement>
    <attribute1>attributeValue</attribute1>
    <attribute2>attributeValue</attribute2>
</childElement>

Existing Code that was outputed (what i don’t want):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <Dennis>
        <Hair Colour="Brown"/>
    </Dennis>
    <!--This is a comment :)-->

What I want it to look like:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <Dennis>
        <Hair>
            <Colour>Brown</colour>
        </Hair>
    </Dennis>
    <!--This is a comment :)-->

*Note: I understand if java won’t be able to make all these indentations and what not. What I DO want it to do is to use the "<open tag>value<close tag>" format.

  • 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-10T00:56:45+00:00Added an answer on June 10, 2026 at 12:56 am

    Simply add an element named attribute1 to the element childElement.

    DOM itself is memory based but you can serialize it to xml and most libraries have pretty printers, that do the indentation.

    Further Reading

    • http://dom4j.sourceforge.net/dom4j-1.6.1/guide.html

    The section Write document to file shows how to format the output with this library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse the xml file with dynamic content using DOM parser in
Parsing an XML file using the Java DOM parser results in: [Fatal Error] os__flag_8c.xml:103:135:
I am using DOM parser in Java to add child nodes into existing nodes.
I am using standard Java DOM parser to process an xml file- I have
I am using this link to generate XML file using DOM. It says that
I need to parse a xml file using JAVA and have to create a
I was trying to parse a collada(.dae) file in java using plane DOM parser.
I am reading an XML file using Stax parser and writing it using DOM
I am using DOM parser to parse xml data, but its taking lots of
I'm using DOM to parse an xml file. And I am having trouble catching

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.