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

  • Home
  • SEARCH
  • 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 7081971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:59:16+00:00 2026-05-28T06:59:16+00:00

I am getting stackoverflowerror while conveting org.w3c.dom.Document to org.dom4j.Document Code : public static org.dom4j.Document

  • 0

I am getting stackoverflowerror while conveting org.w3c.dom.Document to org.dom4j.Document

Code :

public static org.dom4j.Document getDom4jDocument(Document w3cDocument)
    {
        //System.out.println("XMLUtility : Inside getDom4jDocument()");
        org.dom4j.Document dom4jDocument  = null;
        DOMReader xmlReader  = null;
        try{
            //System.out.println("Before conversion of w3cdoc to dom4jdoc");
            xmlReader = new DOMReader();            
            dom4jDocument = xmlReader.read(w3cDocument);
            //System.out.println("Conversion complete");
        }catch(Exception e){
            System.out.println("General Exception :- "+e.getMessage());
        }
        //System.out.println("XMLUtility : getDom4jDocument() Finished");
        return dom4jDocument;   
    } 

log :

java.lang.StackOverflowError
    at java.lang.String.indexOf(String.java:1564)
    at java.lang.String.indexOf(String.java:1546)
    at org.dom4j.tree.NamespaceStack.getQName(NamespaceStack.java:158)
    at org.dom4j.io.DOMReader.readElement(DOMReader.java:184)
    at org.dom4j.io.DOMReader.readTree(DOMReader.java:93)
    at org.dom4j.io.DOMReader.readElement(DOMReader.java:226)
    at org.dom4j.io.DOMReader.readTree(DOMReader.java:93)
    at org.dom4j.io.DOMReader.readElement(DOMReader.java:226)

Actually i want to convert XML to string by using org.dom4j.Document’s asXML method. Is this conversion possible without converting org.w3c.dom.Document to org.dom4j.Document ? How ?

  • 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-28T06:59:17+00:00Added an answer on May 28, 2026 at 6:59 am

    when handling a heavy file, you shouldn’t use a DOM reader, but a SAX one. I assume your goal is to output your document to a string.

    Here you can find some differences between SAX and DOM (source) :

    SAX

    • Parses node by node
    • Doesn’t store the XML in memory
    • We cant insert or delete a node
    • SAX is an event based parser
    • SAX is a Simple API for XML
    • doesn’t preserve comments
    • SAX generally runs a little faster than DOM

    DOM

    • Stores the entire XML document into memory before processing
    • Occupies more memory
    • We can insert or delete nodes
    • Traverse in any direction.
    • DOM is a tree model parser
    • Document Object Model (DOM) API
    • Preserves comments
    • SAX generally runs a little faster than DOM

    You don’t need to produce a model which will need a lot of memory space. You only need to crawl through nodes to output them one by one.

    Here, you will find some code to start with ; then you should implement a tree traversal algorithm.

    Regards

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

Sidebar

Related Questions

I am getting a StackOverflow Error in this code: EDIT [XmlAttribute(ID)] public string ID
Getting Fatal Error while running bin/hadoop namenode -format Using Windows 7 operating system, Under
Getting the above error in following code. How to rectify it. Thanks. Please look
Getting output with Java is pretty easy as you can make use of System.out.print
I'm developing a Baby Names app. I'm getting runtime exception while developing the App.
Getting data from a database table to an object in code has always seemed
Getting an error with my code found HERE ... Which is a culmination of
Getting this error while trying to erase the last element of a list. I
This is program I am writing. I am getting a StackOverFlowError exception when I
Getting this error while I am trying to run /compile/build a Proiject Incompatible Types

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.