appendChild & cloneNode

Discussion in 'XML' started by Chameleon, Jun 1, 2009.

  1. Chameleon

    Chameleon Guest

    The following code display a DIV#help with AJAX loaded XML inside.
    It works fine in W3C Compliant Browsers but not in IE8.
    The problem in IE8 appears in last line.
    Is there an error in my code or an IE8 incompatibility?
    Any workarounds?
    Thanks
    ---------------------------------------------------------
    function openHelp(a) {
    var obj = document.getElementById('help');
    obj.style.display = 'block';

    var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4)
    innerDOM(obj, xmlHttp.responseXML.documentElement);
    }
    xmlHttp.open("GET", 'help.php/' + a, true);
    xmlHttp.send(null);
    }

    function innerDOM(where, root) {
    for (var z = 0; z < root.childNodes.length; z++)
    where.appendChild(root.childNodes[z].cloneNode(true)); // <-- HERE IS
    THE PROBLEM
    }
    --------------------------------------------------------------
    Chameleon, Jun 1, 2009
    #1
    1. Advertising

  2. Chameleon

    David Mark Guest

    On Jun 1, 5:35 pm, Chameleon <> wrote:
    > The following code display a DIV#help with AJAX loaded XML inside.
    > It works fine in W3C Compliant Browsers but not in IE8.
    > The problem in IE8 appears in last line.
    > Is there an error in my code or an IE8 incompatibility?
    > Any workarounds?
    > Thanks
    > ---------------------------------------------------------
    > function openHelp(a) {
    >         var obj = document.getElementById('help');
    >         obj.style.display = 'block';
    >
    >         var xmlHttp = new XMLHttpRequest();
    >         xmlHttp.onreadystatechange = function() {
    >                 if (xmlHttp.readyState == 4)
    >                         innerDOM(obj, xmlHttp.responseXML.documentElement);
    >         }
    >         xmlHttp.open("GET", 'help.php/' + a, true);
    >         xmlHttp.send(null);
    >
    > }
    >
    > function innerDOM(where, root) {
    >         for (var z = 0; z < root.childNodes.length; z++)
    >                 where.appendChild(root.childNodes[z].cloneNode(true));  // <-- HERE IS
    > THE PROBLEM}
    >
    > --------------------------------------------------------------


    It takes a lot more than that to import XML nodes into an HTML DOM.
    It is especially tricky in IE. I suggest you use innerHTML or find
    another approach (e.g. download data instead of markup.)
    David Mark, Jun 1, 2009
    #2
    1. Advertising

  3. Chameleon

    Stevo Guest

    Chameleon wrote:
    > The following code display a DIV#help with AJAX loaded XML inside.
    > It works fine in W3C Compliant Browsers but not in IE8.
    > The problem in IE8 appears in last line.
    > Is there an error in my code or an IE8 incompatibility?
    > Any workarounds?


    You haven't told us what error IE8 gives you.

    > where.appendChild(root.childNodes[z].cloneNode(true)); // <--


    Have MS defined where as a reserved word perhaps? Knowing what error IE8
    reports would have avoided this silly suggestion ;-)
    Stevo, Jun 1, 2009
    #3
  4. Chameleon

    RobG Guest

    On Jun 2, 8:24 am, Stevo <> wrote:
    > Chameleon wrote:

    [...]
    > >         where.appendChild(root.childNodes[z].cloneNode(true));    // <--

    >
    > Have MS defined where as a reserved word perhaps? Knowing what error IE8
    > reports would have avoided this silly suggestion ;-)


    where was declared in the formal parameter list of the function
    declaration (which you trimmed). :)


    --
    Rob
    RobG, Jun 1, 2009
    #4
  5. Chameleon

    NickFitz Guest

    On Jun 1, 10:35 pm, Chameleon <> wrote:
    > The following code display a DIV#help with AJAX loaded XML inside.
    > It works fine in W3C Compliant Browsers but not in IE8.
    > The problem in IE8 appears in last line.
    > Is there an error in my code or an IE8 incompatibility?
    > Any workarounds?
    > Thanks
    > ---------------------------------------------------------
    > function openHelp(a) {
    >         var obj = document.getElementById('help');
    >         obj.style.display = 'block';
    >
    >         var xmlHttp = new XMLHttpRequest();
    >         xmlHttp.onreadystatechange = function() {
    >                 if (xmlHttp.readyState == 4)
    >                         innerDOM(obj, xmlHttp.responseXML.documentElement);
    >         }
    >         xmlHttp.open("GET", 'help.php/' + a, true);
    >         xmlHttp.send(null);
    >
    > }
    >
    > function innerDOM(where, root) {
    >         for (var z = 0; z < root.childNodes.length; z++)
    >                 where.appendChild(root.childNodes[z].cloneNode(true));  // <-- HERE IS
    > THE PROBLEM}
    >
    > --------------------------------------------------------------


    Slightly superficial explanation: on Internet Explorer, the
    responseXML object is an XML Document containing XML Nodes, whereas
    the page into which you are trying to insert the content is an HTML
    Document containing HTML Nodes; in the wacky world of Microsoft XML
    and HTML have separate and incompatible implementations (even within
    the browser), whereas other browsers such as Firefox use one
    implementation for both cases.

    You are probably better off using the responseText and innerHTML
    properties, as David Mark suggests, even though it is less
    satisfactory from a purist perspective :-(

    Regards,

    Nick.
    --
    Nick Fitzsimons
    http://www.nickfitz.co.uk/
    NickFitz, Jun 2, 2009
    #5
  6. Joe Kesselman, Jun 2, 2009
    #6
  7. Chameleon

    NickFitz Guest

    On Jun 2, 1:31 pm, Joe Kesselman <>
    wrote:
    > When nodes come from different documents, you should probably be using
    > the importNode operation.
    >
    > http://www.w3.org/DOM/faq.html#ownerdoc


    That still won't work on IE. XML nodes, implemented by MSXML, are a
    different and incompatible kind of COM component to the HTML nodes
    implemented in MSHTML :-(
    NickFitz, Jun 2, 2009
    #7
  8. On Jun 2, 2:24 pm, NickFitz wrote:
    > On Jun 2, 1:31 pm, Joe Kesselman wrote:
    >
    >> When nodes come from different documents, you should
    >> probably be using the importNode operation.

    >
    >> http://www.w3.org/DOM/faq.html#ownerdoc

    >
    > That still won't work on IE. XML nodes, implemented by MSXML,
    > are a different and incompatible kind of COM component to
    > the HTML nodes implemented in MSHTML :-(


    That would not necessarily matter as the - importNode - method would
    be able to create new nodes in the target document based upon the
    nodes it received as arguments. Indeed the - importNode - method is
    required to create new nodes rather than directly employing its
    argument nodes.

    Of course the reason that won't work with IE is that Microsoft DOMs
    (at very lest the HTML DOM that is the target here) does not have the
    - importNode - method implemented.

    On the other hand, the existence of an - importNode - method in the
    W3C Core DOM does appear to be a fair indicator that the ability to
    directly append nodes from one document into another should not be
    expected to be available. This impression is reinforced by observing
    that the - appendChild - method is allowed/expected to throw a
    "WRONG_DOCUMENT_ERR" "if newChild was created from a different
    document than the one that created this node". So there is no reason
    for expecting to be able to append nodes from an XML document into an
    HTML document, even if it is possible to point to some environments
    where it can be done.

    Richard.
    Richard Cornford, Jun 2, 2009
    #8
  9. >> That still won't work on IE. XML nodes, implemented by MSXML,
    >> are a different and incompatible kind of COM component to
    >> the HTML nodes implemented in MSHTML :-(

    >
    > That would not necessarily matter as the - importNode - method would
    > be able to create new nodes in the target document based upon the
    > nodes it received as arguments. Indeed the - importNode - method is
    > required to create new nodes rather than directly employing its
    > argument nodes.


    Exactly. importNode()'s job is to read the data from the source node
    (using the public DOM APIs) and to recreate equivalent nodes in the
    target DOM.

    > Of course the reason that won't work with IE is that Microsoft DOMs
    > (at very lest the HTML DOM that is the target here) does not have the
    > - importNode - method implemented.


    .... Which means you have to go back to the solution used before
    importNode() was added: Write your own importing subroutine which walks
    the source tree and builds equivalent nodes in the target. Easy with
    recursion; more difficult but sometimes more efficient with an iterative
    engine.

    > So there is no reason
    > for expecting to be able to append nodes from an XML document into an
    > HTML document, even if it is possible to point to some environments
    > where it can be done.


    Or from an XML document to an XML document, unless you know the DOM
    implementations can work happily with each other. Basically, if you
    haven't written (or examined) the low-level code which created the DOMs,
    you'd better plan on importing.

    FAQ, as cited.
    Joe Kesselman, Jun 2, 2009
    #9
  10. Chameleon

    David Mark Guest

    On Jun 2, 4:01 pm, Joe Kesselman <>
    wrote:
    > >> That still won't work on IE. XML nodes, implemented by MSXML,
    > >> are a different and incompatible kind of COM component to
    > >> the HTML nodes implemented in MSHTML :-(

    >
    > > That would not necessarily matter as the - importNode - method would
    > > be able to create new nodes in the target document based upon the
    > > nodes it received as arguments. Indeed the - importNode - method is
    > > required to create new nodes rather than directly employing its
    > > argument nodes.

    >
    > Exactly. importNode()'s job is to read the data from the source node
    > (using the public DOM APIs) and to recreate equivalent nodes in the
    > target DOM.


    And it does so poorly (and not at all in IE.)

    >
    > > Of course the reason that won't work with IE is that Microsoft DOMs
    > > (at very lest the HTML DOM that is the target here) does not have the
    > > - importNode - method implemented.

    >
    > ... Which means you have to go back to the solution used before
    > importNode() was added: Write your own importing subroutine which walks
    > the source tree and builds equivalent nodes in the target. Easy with
    > recursion; more difficult but sometimes more efficient with an iterative
    > engine.


    It's been done to death. All a waste of time. Use innerHTML or JSON.

    [snip]
    David Mark, Jun 2, 2009
    #10
  11. Chameleon

    Jorge Guest

    On Jun 2, 10:11 pm, David Mark <> wrote:
    >
    > (...) Use innerHTML or JSON.


    JSON ? What's JSON ?

    Oh well, I'll see it in the good old great cljs FAQ :)

    http://www.google.com/search?&q=site:jibbering.com/faq/ json

    Ooops:

    "Your search - site:jibbering.com/faq/ json - did not match any
    documents."

    Pathetic, pitiful...

    --
    Jorge.
    Jorge, Jun 2, 2009
    #11
  12. Chameleon

    David Mark Guest

    On Jun 2, 4:36 pm, Jorge <> wrote:
    > On Jun 2, 10:11 pm, David Mark <> wrote:
    >
    >
    >
    > > (...) Use innerHTML or JSON.

    >
    > JSON ? What's JSON ?
    >
    > Oh well, I'll see it in the good old great cljs FAQ :)


    You'll see it on Google as well.

    >
    > http://www.google.com/search?&q=site:jibbering.com/faq/ json
    >
    > Ooops:
    >
    > "Your search - site:jibbering.com/faq/ json - did not match any
    > documents."
    >
    > Pathetic, pitiful...


    So try again. Don't restrict your search to jibbering.com as there is
    no JSON FAQ there.

    HTH.
    David Mark, Jun 3, 2009
    #12
  13. Chameleon

    RobG Guest

    On Jun 3, 6:36 am, Jorge <> wrote:
    > On Jun 2, 10:11 pm, David Mark <> wrote:
    >
    >
    >
    > > (...) Use innerHTML or JSON.

    >
    > JSON ? What's JSON ?
    >
    > Oh well, I'll see it in the good old great cljs FAQ :)
    >
    > http://www.google.com/search?&q=site:jibbering.com/faq/ json
    >
    > Ooops:
    >
    > "Your search - site:jibbering.com/faq/ json - did not match any
    > documents."


    Not surprising, there aren't any frequently asked questions about JSON
    here.


    > Pathetic, pitiful...


    Not at all, quite reasonable in fact. An FAQ is for *frequently*
    asked questions, I don't see frequent questions about JSON here. If
    the purpose of the clj FAQ was general javascript topics, it would be
    perhaps 50 times larger that it is, at least.

    In any case, if you think an item on JSON is required, write one and
    post it here for review and possible inclusion in the FAQ.


    --
    Rob
    RobG, Jun 3, 2009
    #13
  14. Chameleon

    Jorge Guest

    On Jun 3, 3:00 am, RobG <> wrote:
    > (...)
    > In any case, if you think an item on JSON is required, write one and
    > post it here for review and possible inclusion in the FAQ.


    Again ? Ok, here it goes:

    On Jun 1, 12:01 pm, Jorge <> wrote:
    > -----------------------------------------------------------------------
    > FAQ Topic - What online resources are available?
    > -----------------------------------------------------------------------
    >
    > http://crockford.com/javascript/
    >
    > JSON: http://www.JSON.org/
    > JSLINT: http://www.JSLint.com/
    > JSMIN: http://javascript.crockford.com/jsmin.html
    > JSMIN: http://fmarcia.info/jsmin/test.html
    > (...)


    HTH,

    --
    Jorge.
    Jorge, Jun 3, 2009
    #14
  15. Jorge wrote:
    > On Jun 2, 10:11 pm, David Mark <> wrote:
    >> (...) Use innerHTML or JSON.

    >
    > JSON ? What's JSON ?
    >
    > Oh well, I'll see it in the good old great cljs FAQ :)
    >
    > http://www.google.com/search?&q=site:jibbering.com/faq/ json
    >
    > Ooops:
    >
    > "Your search - site:jibbering.com/faq/ json - did not match any
    > documents."
    >
    > Pathetic, pitiful...
    >


    Yes, and LOL funny.

    Make sure that you type the search term criteria first, before the site
    filter.

    Like this:-
    json site:jibbering.com/

    LOL.

    Garrett

    --
    The official comp.lang.javascript FAQ:
    http://jibbering.com/faq/
    Garrett Smith, Jun 3, 2009
    #15
  16. Garrett Smith wrote:
    > Jorge wrote:
    >> On Jun 2, 10:11 pm, David Mark <> wrote:


    [...]

    >> "Your search - site:jibbering.com/faq/ json - did not match any
    >> documents."
    >>
    >> Pathetic, pitiful...
    >>

    >
    > Yes, and LOL funny.
    >
    > Make sure that you type the search term criteria first, before the site
    > filter.
    >
    > Like this:-
    > json site:jibbering.com/
    >


    It does seem to work the other way, too. Guess it isn't funny after all.
    Just annoying.

    Garrett

    --
    The official comp.lang.javascript FAQ:
    http://jibbering.com/faq/
    Garrett Smith, Jun 3, 2009
    #16
  17. RobG wrote:
    > On Jun 3, 6:36 am, Jorge <> wrote:
    >> On Jun 2, 10:11 pm, David Mark <> wrote:


    [...]

    >
    > Not at all, quite reasonable in fact. An FAQ is for *frequently*
    > asked questions, I don't see frequent questions about JSON here. If
    > the purpose of the clj FAQ was general javascript topics, it would be
    > perhaps 50 times larger that it is, at least.
    >
    > In any case, if you think an item on JSON is required, write one and
    > post it here for review and possible inclusion in the FAQ.
    >
    >


    As stated in the "comments and suggestions" entry:

    | A Draft Proposal for the FAQ is requested and appreciated.

    Garrett

    --
    The official comp.lang.javascript FAQ:
    http://jibbering.com/faq/
    Garrett Smith, Jun 3, 2009
    #17
  18. Chameleon

    Jorge Guest

    On Jun 3, 9:00 am, Garrett Smith <> wrote:
    > (...)
    > Make sure that you type the search term criteria first, before the site
    > filter.
    >
    > Like this:-
    > json site:jibbering.com/
    > (...)


    Oh, how clever ! But that doesn't restrict the search to the FAQ...
    and in fact, none of the results are in the FAQ. So, still, pathetic
    and pitiful.

    Thanks,

    --
    Jorge.
    Jorge, Jun 3, 2009
    #18
  19. Chameleon

    Jorge Guest

    On Jun 3, 9:06 am, Garrett Smith <> wrote:
    > (...)
    > As stated in the "comments and suggestions" entry:
    >
    > | A Draft Proposal for the FAQ is requested and appreciated.


    Requested might me, but obviously not much appreciated.

    Just in case, here it goes: my proposal (again): ADD THIS, THANKS :


    -----------------------------------------------------------------------
    FAQ Topic - What online resources are available?
    -----------------------------------------------------------------------

    (NEW) VIDEO: Changes to JavaScript, Part 1: EcmaScript 5
    Presented by Mark Miller, Waldemar Horwat, and Mike Samuel.
    http://www.youtube.com/watch?v=Kq4FpMe6cRs

    http://crockford.com/javascript/

    JSON: http://www.JSON.org/
    JSLINT: http://www.JSLint.com/
    JSMIN: http://javascript.crockford.com/jsmin.html
    JSMIN: http://fmarcia.info/jsmin/test.html

    VIDEOS about JavaScript:
    http://developer.yahoo.com/yui/theater/ :

    The JavaScript programming language:
    http://video.yahoo.com/video/play?vid=111593
    http://video.yahoo.com/video/play?vid=111594
    http://video.yahoo.com/video/play?vid=111595
    http://video.yahoo.com/video/play?vid=111596

    Advanced JavaScript:
    http://video.yahoo.com/video/play?vid=111585
    http://video.yahoo.com/video/play?vid=111586
    http://video.yahoo.com/video/play?vid=111587

    An Inconvenient API: The Theory of the DOM:
    http://video.yahoo.com/video/play?vid=111582
    http://video.yahoo.com/video/play?vid=111583
    http://video.yahoo.com/video/play?vid=111584

    JavaScript: The Good Stuff:
    http://video.yahoo.com/video/play?vid=630959

    The State of Ajax:
    http://yuiblog.com/blog/2007/11/06/video-crockford

    Web Forward:
    http://video.yahoo.com/watch/3730137/10250950

    Ajax Performance:
    http://video.yahoo.com/watch/4141759/11157560

    Gears and the mashup problem:
    http://video.google.com/videoplay?docid=452089494323007214

    JavaScript: The Good Parts. (VIDEO)
    http://www.youtube.com/watch?v=hQVTIJBZook


    -----------------------------------------------------------------------
    FAQ Topic - What books are recommended for javascript?
    -----------------------------------------------------------------------

    "JavaScript: The Good Parts", by Douglas Crockford.
    ISBN 10: 0-596-51774-2 | ISBN 13: 9780596517748
    http://oreilly.com/catalog/9780596517748/


    --
    Jorge.
    Jorge, Jun 3, 2009
    #19
  20. Chameleon

    Jorge Guest

    On Jun 3, 9:00 am, Garrett Smith <> wrote:
    > (...)
    > Yes, and LOL funny.
    > (...)


    LOL and funny ? That wasn't supposed to be funny, or did you see any
    smiley ? That's pathetic and pitiful for a *JAVASCRIPT* FAQ...

    --
    Jorge.
    Jorge, Jun 3, 2009
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TW9ua2V5Qm95?=
    Replies:
    2
    Views:
    434
    =?Utf-8?B?TW9ua2V5Qm95?=
    Jun 6, 2004
  2. Sullivan WxPyQtKinter
    Replies:
    0
    Views:
    1,900
    Sullivan WxPyQtKinter
    Mar 14, 2006
  3. itsme

    XmlDocument and cloneNode

    itsme, Oct 14, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    143
    itsme
    Oct 14, 2003
  4. Olorin

    cloneNode/appendChild and children

    Olorin, Apr 30, 2007, in forum: Javascript
    Replies:
    4
    Views:
    176
    Olorin
    May 3, 2007
  5. Chameleon

    appendChild & cloneNode

    Chameleon, Jun 1, 2009, in forum: Javascript
    Replies:
    26
    Views:
    247
    Thomas 'PointedEars' Lahn
    Jun 3, 2009
Loading...

Share This Page