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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:17:29+00:00 2026-05-17T22:17:29+00:00

In an open source project I maintain, we have at least three different ways

  • 0

In an open source project I maintain, we have at least three different ways of reading, processing and writing XML files and I would like to standardise on a single method for ease of maintenance and stability.

Currently all of the project files use XML from the configuration to the stored data, we’re hoping to migrate to a simple database at some point in the future but will still need to read/write some form of XML files.

The data is stored in an XML format that we then use a XSLT engine (Saxon) to transform into the final HTML files.

We currently utilise these methods:
– XMLEventReader/XMLOutputFactory (javax.xml.stream)
– DocumentBuilderFactory (javax.xml.parsers)
– JAXBContext (javax.xml.bind)

Are there any obvious pros and cons to each of these?
Personally, I like the simplicity of DOM (Document Builder), but I’m willing to convert to one of the others if it makes sense in terms of performance or other factors.

Edited to add:
There can be a significant number of files read/written when the project runs, between 100 & 10,000 individual files of around 5Kb each

  • 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-17T22:17:29+00:00Added an answer on May 17, 2026 at 10:17 pm

    It depends on what you are doing with the data.

    If you are simply performing XSLT transforms on XML files to produce HTML files then you may not need to touch a parser directly:

    import java.io.File;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            TransformerFactory tf = TransformerFactory.newInstance();    
            StreamSource xsltTransform = new StreamSource(new File("xslt.xml"));
            Transformer transformer = tf.newTransformer(xsltTransform);
    
            StreamSource source = new StreamSource(new File("source.xml"));
    
            StreamResult result = new StreamResult(new File("result.html"));
            transformer.transform(source, result);            
        }
    
    }
    

    If you need to make changes to the input document before you transform it, DOM is a convenient mechanism for doing this:

    import java.io.File;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;
    import org.w3c.dom.Document;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            TransformerFactory tf = TransformerFactory.newInstance();
            StreamSource xsltTransform = new StreamSource(new File("xslt.xml"));
            Transformer transformer = tf.newTransformer(xsltTransform);
    
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document document = db.parse(new File("source.xml"));
            // modify the document
            DOMSource source = new DOMSource(document);
    
            StreamResult result = new StreamResult(new File("result.html"));
            transformer.transform(source, result);  
        }
    
    }
    

    If you prefer a typed model to make changes to the data then JAXB is a perfect fit:

    import java.io.File;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Unmarshaller;
    import javax.xml.bind.util.JAXBSource;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            TransformerFactory tf = TransformerFactory.newInstance();
            StreamSource xsltTransform = new StreamSource(new File("xslt.xml"));
            Transformer transformer = tf.newTransformer(xsltTransform);
    
            JAXBContext jc = JAXBContext.newInstance("com.example.model");
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            Model model = (Model) unmarshaller.unmarshal(new File("source.xml"));
            // modify the domain model
            JAXBSource source = new JAXBSource(jc, model);
    
            StreamResult result = new StreamResult(new File("result.html"));
            transformer.transform(source, result);            
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For an open source project I have I am writing an abstraction layer on
I currently mantain an open-source project hosted in SourceForge. My project is written in
I'm building an open source project that uses python and c++ in Windows. I
recently I downloaded this open source project and I am trying to compile it.
I'm running an open source project and every now and then Chinese users report
Or any open source project which utilize collective intelligence extensively?.
For an open source project I am looking for a good, simple implementation of
Is that possible to switch an Open Source Project license from GPL to LGPL
I am looking for an open-source project involving c++ GUI(s) working with a database.
If I was going to start an open source project using Python what version

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.