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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:26:51+00:00 2026-05-26T02:26:51+00:00

I remember well that using the DOM implementation to create new HTML elements on

  • 0

I remember well that using the DOM implementation to create new HTML elements on a document was considered to be very much slower than assigning an HTML string to the ‘innerHTML’ property of the applicable HTML element.

Does the same apply when authoring XML documents using JavaScript? Rather than using the DOM implementation’s various create methods, would it be faster to just generate the XML string and parsing it?

Just something I wondered about…. 🙂

*EDIT – Added an example *

Which is faster? (I’ll be using jQuery’s parseXML function to do the parsing example):

var myXdoc = $.parseXML("<person><name>Bob</name><relation>Uncle</relation>");

Or

var myXdoc

if (window.ActiveXObject) {
    myXdoc = new ActiveXObject("Microsoft.XMLDOM");
    myXdoc.async = false;
}
else if (document.implementation && document.implementation.createDocument)
    myXdoc = document.implementation.createDocument("", "", null);

var p = myXdoc.documentElement.appendChild(myXdoc.createElement("person"));
var n = p.appendChild(myXdoc.createElement("name"));
n.appendChild(myXdoc.createTextNode("Bob"));
var r = p.appendChild(myXdoc.createElement("relation"));
r.appendChild(myXdoc.createTextNode("Uncle"));
  • 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-26T02:26:52+00:00Added an answer on May 26, 2026 at 2:26 am

    The first thing we have to know why createDocument() might be slow. The reason is that the DOM is alive and if you are modifying it, it triggers a re-validation of the DOM tree and probably a redraw of the site. Every time. But we could avoid this unnecessary re-validation and re-draw by using createDocumentFragment(). The DocumentFragment isn’t part of the DOM and so it wont trigger any events. So you can build your complete DOM part and in the last step append it to the DOM tree. I think it’s the fastest way to create large DOM parts.

    UPDATE
    I tested it in Firefox 7 using Firebug. The code:

    console.time("a");
    for(var i=0; i<1000; i++) {
    $.parseXML("<person><name>Bob</name><relation>Uncle</relation></person>")
    }
    console.timeEnd("a");
    
    console.time("b");
    for(var i=0; i<1000; i++) {
    var myXdoc
    if (document.createDocumentFragment) {
        myXdoc = document.createDocumentFragment();
    }
    var p = myXdoc.appendChild(document.createElement("person"));
    var n = p.appendChild(document.createElement("name"));
    n.appendChild(document.createTextNode("Bob"));
    var r = p.appendChild(document.createElement("relation"));
    r.appendChild(document.createTextNode("Uncle"));
    }
    console.timeEnd("b");
    

    The result: “a” about 140ms and “b” about 35ms. So the string parse version is slower.

    UPDATE2
    It’s very likely that the second variant is faster in any other browser, too. Because the parse method has to build the DOM object too and it’s very likely that it uses the same methods (e.g.: document.createElement). So the parse method can’t be faster. But it’s slower because it has first to parse the string.

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

Sidebar

Related Questions

Remember, this is using python. Well, I was fiddling around with an app I
I have a tabbed jquery slider that I'm using to display elements of an
For my lastest project I'm using https://github.com/hassox/rails_warden . It suits my needs very well
I remember that when using Boost.Spirit and for the std::function addition to C++0x, you
I'm using the well-known pattern to create an UIImage from an UIView : +
I remember reading somewhere that you can provide your own icons without having them
(I'm using Visual Studio 2008, though I remember having similar problems with older versions
I can't see anything on here but I do remember being told that If
After almost two years of using DVCS, it seems that one inherent flaw is
...instead of using the Atom syndication format? Atom is a well-defined , general-purpose XML

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.