Bug Tracker

Ticket #9602 (closed bug: duplicate)

Opened 4 years ago

Last modified 3 years ago

Exception when adding a new node in XML.

Reported by: rcrathore Owned by: rcrathore
Priority: low Milestone: 1.next
Component: manipulation Version: 1.6.1
Keywords: Cc:
Blocking: Blocked by:

Description

jsFiddle URL :  http://jsfiddle.net/rcrathore/Y8DpM/[1]

I am trying to add a new node in XML using jQuery. Following code works fine in Firefox, Safari and Chrome but giving error in IE8:

<div id="result"> </div>

<div id="result2"> </div>

<script type="text/javascript"> <!--

var xml = "<root><node1><node2>TEXT1</node2></node1></root>" ; var $xml = $($.parseXML(xml)) ;

var newData = "<node3>234</node3>" ; var $newData = $($.parseXML(newData)); var newNode = null;

if (typeof document.importNode == 'function') {

newNode = document.importNode($newData.find('node3').get(0),true);

} else {

newNode = $newData.find('node3').get(0)

}

try {

$(newNode).appendTo($xml.find("node2")); /* expected TEXT1234*/ $("div#result").html($xml.text());

/* expected 234*/ $("div#result2").html($xml.find("root > node1 > node2 > node3").text());

} catch (e) {

alert(e) ; $("div#result").html("Error: " + e.description);

}

--> </script>

The error description on IE8 is "Wrong number of arguments or invalid property assignment".

[1]:  http://jsfiddle.net/rcrathore/Y8DpM/

Change History

comment:1 Changed 4 years ago by rcrathore

The code works in all browsers if I replace appendTo line

$(newNode).appendTo($xml.find("node2"));

by :

$xml.find("node2").get(0).appendChild(newNode) ;

comment:2 Changed 3 years ago by Isaac

Related?

//Crash in IE
var $xml = $('<xml />').append($('<root />').append('<child />'));
//Works in IE
var $xml = $('<exml />').append($('<root />').append('<child />'));

comment:3 Changed 3 years ago by timmywil

  • Owner set to rcrathore
  • Priority changed from undecided to low
  • Status changed from new to pending
  • Component changed from unfiled to manipulation

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on  http://jsfiddle.net that reproduces the issue experienced to help us assess your ticket.

Additionally, test against the jQuery (edge) version to ensure the issue still exists.

comment:4 Changed 3 years ago by rcrathore

  • Status changed from pending to new

Isaac, timmywil:

  1. Not sure if Isaac's example is related.
  1. Not sure what can be reduced in my test case. I think it is already very compact. A root element has node2 and node2 and I am inserting a new node (node3) under node2.
Version 0, edited 3 years ago by rcrathore (next)

comment:5 Changed 3 years ago by kabel

comment:6 Changed 3 years ago by rcrathore

Thank you! kabel

comment:7 Changed 3 years ago by timmywil

  • Status changed from new to closed
  • Resolution set to duplicate

comment:8 Changed 3 years ago by timmywil

Duplicate of #9370.

Note: See TracTickets for help on using tickets.