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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:41:30+00:00 2026-05-17T01:41:30+00:00

I have been using DOM for a long time and as such DOM parsing

  • 0

I have been using DOM for a long time and as such DOM parsing performance wise has been pretty good. Even when dealing with XML of about 4-7 MB the parsing has been fast. The issue we face with DOM is the memory footprint which become huge as soon as we start dealing with large XMLs.

Lately I tried moving to Stax (Streaming parsers for XML) which are supposed top be second generation parsers (reading about Stax it said its the fastest parser now). When I tried Stax parser for large XML for about 4MB memory footprint definitely reduced drastically but time take to parse entire XML and create java object out of it increased almost by 5 times over DOM.

I used sjsxp.jar implementation of Stax.

I can deduce to some extent logically that performance may not be extremely good due to streaming nature of the parser but a reduction of 5 time (e.g. DOM takes about 8 seconds to build object for this XML, whereas Stax parsing took about 40 seconds on average) is definitely not going to be acceptable.

Am I missing some point here completely as I am not able to come to terms with these performance numbers

  • 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-17T01:41:30+00:00Added an answer on May 17, 2026 at 1:41 am
    package parsers;
    
    /**
     *
     * @author Arthur Kushman
     */
    
    import java.io.File;
    import java.io.IOException;
    
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    
    import org.w3c.dom.Document;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.Element;
    
    
    public class DOMTest {
    
      public static void main(String[] args) {
      long time1 = System.currentTimeMillis();
       try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(new File("/Users/macpro/Desktop/myxml.xml"));
        doc.getDocumentElement().normalize();
        // System.out.println("Root Element: "+doc.getDocumentElement().getNodeName());
        NodeList nodeList = doc.getElementsByTagName("input");
        // System.out.println("Information of all elements in input");
    
        for (int s=0;s<nodeList.getLength();s++) {
          Node firstNode = nodeList.item(s);
          if (firstNode.getNodeType() == Node.ELEMENT_NODE) {
            Element firstElement = (Element)firstNode;
            NodeList firstNameElementList = firstElement.getElementsByTagName("href");
            Element firstNameElement = (Element)firstNameElementList.item(0);
            NodeList firstName = firstNameElement.getChildNodes();
            System.out.println("First Name: "+((Node)firstName.item(s)).getNodeValue());        
          }
        }
    
    
       } catch (Exception ex) {
        System.out.println(ex.getMessage());
        System.exit(1);
       }
      long time2 = System.currentTimeMillis() - time1;
      System.out.println(time2);
      }
    
    }
    

    45 mills

    package parsers;
    
    /**
     *
     * @author Arthur Kushman
     */
    import javax.xml.stream.*;
    import java.io.*;
    import javax.xml.namespace.QName;
    
    public class StAXTest {
    
      public static void main(String[] args) throws Exception {
      long time1 = System.currentTimeMillis();
        XMLInputFactory factory = XMLInputFactory.newInstance();
        // factory.setXMLReporter(myXMLReporter);
        XMLStreamReader reader = factory.createXMLStreamReader(
                new FileInputStream(
                new File("/Users/macpro/Desktop/myxml.xml")));
    
        /*String encoding = reader.getEncoding();
    
        System.out.println("Encoding: "+encoding);
    
        while (reader.hasNext()) {
          int event = reader.next();
          if (event == XMLStreamConstants.START_ELEMENT) {
            QName element = reader.getName();
            // String text = reader.getText();
            System.out.println("Element: "+element);
            // while (event != XMLStreamConstants.END_ELEMENT) {
              System.out.println("Text: "+reader.getLocalName());
            // }
          }
        }*/
    
      try {
        int inElement = 0;
        for (int event = reader.next();event != XMLStreamConstants.END_DOCUMENT;
        event = reader.next()) {
          switch (event) {
            case XMLStreamConstants.START_ELEMENT:
              if (isElement(reader.getLocalName(), "href")) {
                inElement++;
              }
              break;
            case XMLStreamConstants.END_ELEMENT:
              if (isElement(reader.getLocalName(), "href")) {
                inElement--;
                if (inElement == 0) System.out.println();
              }
              break;
            case XMLStreamConstants.CHARACTERS:
              if (inElement>0) System.out.println(reader.getText());
              break;
            case XMLStreamConstants.CDATA:
              if (inElement>0)  System.out.println(reader.getText());
              break;
          }
        }
        reader.close();
      } catch (XMLStreamException ex) {
        System.out.println(ex.getMessage());
        System.exit(1);
      }
        // System.out.println(System.currentTimeMillis());
        long time2 = System.currentTimeMillis() - time1;
        System.out.println(time2);
     }
    
      public static boolean isElement(String name, String element) {
        if (name.equals(element)) return true;
        return false;
      }
    
    }
    

    23 mills

    StAX wins =)

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

Sidebar

Related Questions

I have been using Eclipse as an IDE for a short amount of time
We have been using Scrum for around 9 months and it has largely been
We have been using CruiseControl for quite a while with NUnit and NAnt. For
I have been using PHP and JavaScript for building my dad's website. He wants
I have been using Castle MonoRail for the last two years, but in a
I have been using C# for a while now, and going back to C++
I have been using ASP.NET for years, but I can never remember when using
I have been using Ruby for a while now and I find, for bigger
I have been using IoC for a little while now and I am curious
I have been using the CSLA framework for couple of years now for windows

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.