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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:37:47+00:00 2026-05-27T16:37:47+00:00

Is there a standardized way (i.e., code pattern, or, even better, open source library)

  • 0

Is there a “standardized” way (i.e., code pattern, or, even better, open source library) in Java for dynamically flattening (“shredding”) a hierarchical XML file, of large size and unknown structure, with output not redirected to an RDBMS but directly accessible?

I am looking at a transformation like the one mentioned in this question, but all the code examples I have seen use some SQL command to inject the flattened XML input to a database table, via an RDBMS (e.g., MySQL).

What I would like to do is progressively extract the XML data into a string, or, at least, into a text file, which could be post-processed afterwards, without going through any RDBMS.

EDIT:

After working further on the issue, there are a couple of solutions using XSLT (including a fully parameterizable one) in this question.

  • 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-27T16:37:47+00:00Added an answer on May 27, 2026 at 4:37 pm

    You could do it with JDOM (see example below, jdom.jar has to be on the classpath). But beware, the whole dom is in memory. If the XML is bigger you should use XSLT or a SAX parser.

    import java.io.IOException;
    import java.io.StringReader;
    
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.input.SAXBuilder;
    import org.junit.Test;
    
    public class JDomFlatten {
    
    @Test
    public void testFlatten() {
        final String xml = "<grandparent name=\"grandpa bob\">"//
                + "<parent name=\"papa john\">"//
                + "<children>"//
                + "<child name=\"mark\" />"//
                + "<child name=\"cindy\" />"//
                + "</children>"//
                + "</parent>"//
                + "<parent name=\"papa henry\">"// 
                + "<children>" //
                + "<child name=\"mary\" />"//
                + "</children>"//
                + "</parent>" //
                + "</grandparent>";
        final StringReader stringReader = new StringReader(xml);
        final SAXBuilder builder = new SAXBuilder();
        try {
            final Document document = builder.build(stringReader);
            final Element grandparentElement = document.getRootElement();
            final StringBuilder outString = new StringBuilder();
            for (final Object parentElementObject : grandparentElement.getChildren()) {
                final Element parentElement = (Element) parentElementObject;
                for (final Object childrenElementObject : parentElement.getChildren()) {
                    final Element childrenElement = (Element) childrenElementObject;
                    for (final Object childElementObject : childrenElement.getChildren()) {
                        final Element childElement = (Element) childElementObject;
    
                        outString.append(grandparentElement.getAttributeValue("name"));
                        outString.append(" ");
                        outString.append(parentElement.getAttributeValue("name"));
                        outString.append(" ");
                        outString.append(childElement.getAttributeValue("name"));
                        outString.append("\n");
                    }
                }
    
            }
            System.out.println(outString);
    
        } catch (final JDOMException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (final IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    }
    

    }

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

Sidebar

Related Questions

Is there any standardized way (not language dependent, I need at least C++, Java
Is there a (standardized) way to get the name of the current method using
I code Java/Swing based UI. My dialogs are quite complex and there are many
is there some kind of standardized way which would allow me to make my
is there a standardized way of sending acorss timezone info of users to other
I am writing an open-source library to extract image metadata and store as XMP
Is there a standardized way to sync a collection of Model objects with a
Is there any standardized / libraried / tested way in .NET to to take
is there a standardized way to create jQuery Mobile Apps (with Phonegap) in multiple
Is there a standardized way to set up AD authentication for a web service

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.