Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Traversing XML elements does not work in IE8

    I am a newbie to javascript but here is what I am trying to do. Note that I looked around for an answer but nothing helped.

    I am trying to traverse XML elements but it is not working in IE8. It is working just fine in Firefox though. And by not working I mean it doesn't go inside the loop even though there are elements.

    This is the XML I am trying to traverse:

    Code:
    var $anXml = $('<node id="anID" inline="0" leaf="true">'
    +'<sub_node1>Text \(more text\)</sub_node1>'
    +'<sub_node2>Text \(more text\)</sub_node2>'
    +'</node>');
    Here is the code I am using to traverse:

    Code:
    alert('children before loop: ' + $anXml.children.length);
    $anXml.children().each(function() {
    alert('child traversed!');
    var $aChild = $(this);
    $anotherXml.data(this.nodeName.toLowerCase(), $aChild.html());
    });
    alert('children after loop: ' + $anXml.children.length);
    Here is the output of alerts:

    Code:
    children before loop: 2
    children after loop: 2
    The 'child traversed!' is never displayed.

    Any thoughts would be much appreciated.

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    $anXml.children.length refers to the number of arguments expected by the children function, not to a node count. my jQuery is rusty, but i think you can use $anXml.children().length to find what you're wanting.

    the IE8 problem is different. IE won't recognize unknown tags. you can trick IE into doing so by creating elements with the names of the tags you need before using the routine. this is tricky and non-intuitive, but i think it will work.

    before your code runs execute this:

    Code:
    if("v"=="\v"){
      document.createElement("sub_node1");
      document.createElement("sub_node2");
      document.createElement("node");
    }
    and once that happens, IE8 SHOULD recognize the non-html tags you are trying to use as html.
    Last edited by rnd me; 12-03-2013 at 06:09 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •