Bug Tracker

Opened 5 years ago

Closed 5 years ago

#12048 closed bug (fixed)

[IE6/7/8] xml set attribute

Reported by: sa.cesare@… Owned by: saiwong
Priority: low Milestone: 1.9
Component: attributes Version: 1.8b1
Keywords: ie6 ie7 ie8 Cc:
Blocked by: Blocking:


On line 2572:

// Use this for any attribute in IE6/7
nodeHook =
var ret = elem.getAttributeNode( name );
if ( !ret ) {
  ret = document.createAttribute( name );
  elem.setAttributeNode( ret );

if elem is XML element,you create HTML attribute and set it on XML element- type mismatch exception.
Using elem.ownerDocument would be more correct IMHO.

Change History (18)

comment:1 Changed 5 years ago by dmethvin

Component: unfiledattributes
Keywords: ie6 ie7 ie8 added
Priority: undecidedlow
Status: newopen

I agree that seems wrong. Do you have a test case, just for completeness?

comment:2 Changed 5 years ago by sa.cesare@…

$(new ActiveXObject('msxml2.domdocument').createElement('test')).attr('test', 1)

throws "Type mismatch" exception in IE.

comment:3 Changed 5 years ago by dmethvin

Resolution: invalid
Status: openclosed

Looking at this further, the code only uses nodeHook on non-XML documents. The example you give would apply to cross-document/cross-frame access, which basically never works in oldIE anyway.

comment:4 Changed 5 years ago by sa.cesare@…

I don't know why you close bug. jquery 1.8 still have it. Problem not with IE or not IE -you create HTML attribute and set it non XML element(in case I work with xml). If you want to create attribute use "elem.ownerDocument" to get correct one-simple "document" valid only HTML context. So, it's logical error not directly related to my sample or IE per se.


comment:5 Changed 5 years ago by dmethvin

Do you have a test case from the API level where it would occur? It didn't look to me like nodeHook was used anywhere but oldIE.

comment:6 Changed 5 years ago by sa.cesare@…

We're using Windows XP through company and top version available on XP is IE8. That's real problem,and since you declare IE6+ compatibility,why it's not a bug anymore?

comment:7 Changed 5 years ago by dmethvin

Resolution: invalid
Status: closedreopened

Do you have a test case from the API level where it would occur? I couldn't think of one and that example above is contrived.

comment:8 Changed 5 years ago by dmethvin

Owner: set to sa.cesare@…
Status: reopenedpending

Reopened pending your test case.

comment:9 Changed 5 years ago by sa.cesare@…

Status: pendingnew

Talking sincerely,I can't understand what you mean by "contrived" and "API level" test case.Some example maybe? Handling xml attributes is broken in current release- that's all I can say. I can't set xml attribute on XML element using JQuery for IE browser. I wouldn't call my example "contrived", it's not complete implementation-OK, but it showcase the problem. I create xml element and set attribute using JQuery API: $(element).attr("someAttr", value).

JQuery create HTML attribute: ret = document.createAttribute( name );

and try to set it on XML element passed: elem.setAttributeNode( ret );

but "elem" is not HTML element in my case(it's XML element), so browser throws exception.

There's a simple fix for that problem-use elem.ownerDocument to create attribute: ret = elem.ownerDocument.createAttribute( name );

problem solved! You always will create attribute in correct document context,HTML or XML accordingly.


comment:10 Changed 5 years ago by sa.cesare@…

If you want cross browser test: $((window.ActiveXObject ? new ActiveXObject("msxml2.domdocument") : document.implementation.createDocument("", "", null)).createElement('test')).attr('test', 1)

but it throws exception only in IE.

comment:11 Changed 5 years ago by dmethvin

Status: newpending

Sorry, I am not trying to be difficult. I understand that the code change is small. I am trying to determine how this could be encountered in real code. How did you encounter the problem originally? As I mentioned, I can see this error occurring if a parent window tried to manipulate elements in an iframe in the same domain, but that is generally going to fail in oldIE because of other limitations in those browsers.

comment:12 Changed 5 years ago by sa.cesare@…

Status: pendingnew

Problem encountered lays not in HTML domain at all,it has pure XML context. I create XML document and fill it with elements which will be sent to server after some manipulations through ajax post. I use XML DOM not HTML. Yes, problem you mention occurs by the same reason- different document contexts. But in my case I simply construct XML document using JQuery API. One time JQuery has very solid XML support and I like it. I can use same API for HTML and XML construction(they have very similar nature anyway). Now some glitches appears, all forget XML and focus on HTML. But XML not going away any time soon IMHO,until we not invent some kind of transformation technique a'la XSL pure and elegant(by the way XSL is XML), I mean JSON2JSON,same as XSL=XML2*. Most javascript libraries using JSON2HTML templating,but how about JSON2JSON,JSON2TEXT and alike? Many legacy projects using XML for the reason. Query language is base for transformation, but it's only beginning. But we don't have even that starting point.

comment:13 Changed 5 years ago by mikesherov

Status: newpending

Make a test case on jsfiddle.net or jsbin.com that clearly shows this problem occurring so we can investigate it properly. Thanks!

comment:14 Changed 5 years ago by sa.cesare@…

Status: pendingnew

http://jsfiddle.net/3xM9B/ try it on IE<=7 .

comment:15 Changed 5 years ago by dmethvin

Milestone: None1.9
Status: newopen

comment:16 Changed 5 years ago by gibson042

Owner: changed from sa.cesare@… to saiwong
Status: openassigned

comment:18 Changed 5 years ago by Sai Wong

Resolution: fixed
Status: assignedclosed

Fix #12048. Set attributes for XML fragments. Close gh-965.

Changeset: 2b0e720406c42a4065010ba94e7adb7170ba74c3

Note: See TracTickets for help on using tickets.