Skip to main content

Bug Tracker

Side navigation

#9602 closed bug (duplicate)

Opened June 16, 2011 11:55AM UTC

Closed June 24, 2011 09:13PM UTC

Last modified June 24, 2011 09:13PM UTC

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:
Blocked by: Blocking:
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/

Attachments (0)
Change History (8)

Changed June 16, 2011 12:25PM UTC by rcrathore comment:1

The code works in all browsers if I replace appendTo line

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

by :

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

Changed June 24, 2011 02:49AM UTC by Isaac comment:2

Related?

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

Changed June 24, 2011 01:56PM UTC by timmywil comment:3

component: unfiledmanipulation
owner: → rcrathore
priority: undecidedlow
status: newpending

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.

Changed June 24, 2011 03:34PM UTC by rcrathore comment:4

_comment0: Isaac, timmywil: \ \ 1. Not sure if Isaac's example is related. \ \ 2. 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. \ \ 1308929748318893
status: pendingnew

Isaac, timmywil:

1. Not sure if Isaac's example is related.

2. 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.

3. I will test it with jQuery (edge) version and update this case.

Changed June 24, 2011 05:50PM UTC by kabel comment:5

Duplicate of #9370. Fixed at 1d1cb582c0f744afaa51a63d374b9ffe0f58d1db

Changed June 24, 2011 06:15PM UTC by rcrathore comment:6

Thank you! kabel

Changed June 24, 2011 09:13PM UTC by timmywil comment:7

resolution: → duplicate
status: newclosed

Changed June 24, 2011 09:13PM UTC by timmywil comment:8

Duplicate of #9370.