Skip to main content

Bug Tracker

Side navigation

#220 closed bug (fixed)

Opened September 27, 2006 01:58PM UTC

Closed October 11, 2009 02:16PM UTC

Nathan

Reported by: jaq@ethelred.org Owned by:
Priority: undecided Milestone:
Component: ajax Version:
Keywords: Nathan Cc: Nathan
Blocked by: Blocking:
Description

I am using jQuery to work with XML documents that are parsed in the browser. However using the .attr(String) method fails with an error in IE.

I have tracked down the problem, which appears to be different implementations of 'getAttribute' between the HTML DOM and XMLDOM in IE.

I have attached a patch with a test case and my fix. Unfortunately the fix consists of catching the error and calling the other version of the function, which seems a bit clunky.

Attachments (4)
  • jquery-220-patch.txt (1.4 KB) - added by jaq@ethelred.org September 27, 2006 02:05PM UTC.
  • jquery-220.2.patch (1.4 KB) - added by jaq@ethelred.org September 27, 2006 02:00PM UTC.

    patch for the problem

  • jquery-220.3.patch (1.4 KB) - added by jaq@ethelred.org September 27, 2006 02:02PM UTC.
  • jquery-220.patch (1.4 KB) - added by jaq@ethelred.org September 27, 2006 01:59PM UTC.
Change History (5)

Changed September 27, 2006 02:08PM UTC by jaq@ethelred comment:1

Index: src/jquery/jquery.js
===================================================================
--- src/jquery/jquery.js	(revision 361)
+++ src/jquery/jquery.js	(working copy)
@@ -392,6 +392,14 @@
 	 * @test ok( $('#name').attr('name') == "name", 'Check for name attribute' );
 	 * @test ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
 	 * @test ok( $('#form').attr('action') == "formaction", 'Check for action attribute' );
+	 * @test var xmltext = '<test><child myattr="hello"/></test>';
+	 * var xmldoc;
+	 * try {
+	 * 	xmldoc = new DOMParser().parseFromString(xmltext, 'text/xml');
+	 * } catch(ex) {
+	 *	xmldoc = new ActiveXObject('Microsoft.XMLDOM'); xmldoc.loadXML(xmltext);
+	 * }
+	 * ok( $('child', xmldoc).attr('myattr') == "hello", 'Check for read attribute from XML doc' );
 	 * 
 	 * @name attr
 	 * @type Object
@@ -1824,9 +1832,13 @@
 		if ( fix[name] ) {
 			if ( value != undefined ) elem[fix[name]] = value;
 			return elem[fix[name]];
-		} else if ( elem.getAttribute != undefined ) {
+		} else if ( typeof elem.getAttribute != "undefined" ) {
 			if ( value != undefined ) elem.setAttribute( name, value );
-			return elem.getAttribute( name, 2 );
+			try {
+				return elem.getAttribute( name, 2 );
+			} catch(ex) {
+				return elem.getAttribute(name);
+			}
 		} else {
 			name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
 			if ( value != undefined ) elem[name] = value;

Changed September 27, 2006 02:50PM UTC by jaq@ethelred comment:2

Oh I forgot to say the patch is against SVN revision 361.

Changed October 15, 2006 03:00AM UTC by john comment:3

resolution: → fixed
status: newclosed

This has been fixed in the latest SVN.

Changed November 06, 2006 02:08PM UTC by Nathan comment:4

cc: ""Nathan
component: → 1
keywords: attr xmlNathan
milestone: → 1
priority: → 1
summary: in IE .attr(String) fails with an error on an XMLDOM documentNathan
type: → 1
version: → 1

Changed October 11, 2009 02:16PM UTC by dmethvin comment:5

component: → ajax
description: I am using jQuery to work with XML documents that are parsed in the browser. However using the .attr(String) method fails with an error in IE.\ \ I have tracked down the problem, which appears to be different implementations of 'getAttribute' between the HTML DOM and XMLDOM in IE.\ \ I have attached a patch with a test case and my fix. Unfortunately the fix consists of catching the error and calling the other version of the function, which seems a bit clunky.I am using jQuery to work with XML documents that are parsed in the browser. However using the .attr(String) method fails with an error in IE. \ \ I have tracked down the problem, which appears to be different implementations of 'getAttribute' between the HTML DOM and XMLDOM in IE. \ \ I have attached a patch with a test case and my fix. Unfortunately the fix consists of catching the error and calling the other version of the function, which seems a bit clunky.
need: → Review
priority: → blocker
resolution: → fixed
status: newclosed
type: → bug

Reopened by spammer.