dnewcome / jath

Jath is a simple template language for parsing xml using json markup.
MIT License
68 stars 15 forks source link

Internet Explorer doesn't work #17

Closed lbineau closed 11 years ago

lbineau commented 11 years ago

Hi again, i am facing with a new problem with Internet Explorer. The samples.html code doesn't work in Internet Explorer.

SCRIPT5007: Unable to get value of the property 'text': object is null or undefined 
jath.js, line 111 character 4

It also doesn't work for the code you gave for this issue (https://github.com/dnewcome/jath/issues/16) but the error is different :

SCRIPT16389: Reference to undeclared namespace prefix: 's'.
jath.js, line 67 character 4 -> just in IE7 & 8

SCRIPT438: Object doesn't support property or method 'setProperty' 
jath.js, line 66 character 4 -> all IE versions

Any idea why ?

dnewcome commented 11 years ago

I think I fixed this. I added the ability for the msie code path to use:

xmldoc.setProperty("SelectionNamespaces", .... );

Internally. I think I'm going to change the API to be more consistent with regard to namespaces, but for the time being, you can set:

Jath.namespaces = { 'xyz', 'http://example.com/xyz' };

And this will allow Jath to resolve xyz in IE. You still need to set:

Jath.resolver

For other browsers. I'm going to fix it so that the former covers all cases, but I won't be able to do that for a few days. In the meantime, just using both methods should work for you. Hopefully this makes sense to you. Your actual test data is part of the test case under:

tests/qunit/case-issue.js

So you should be able to see exactly how it should work. You can run the test by opening up

qunit-test.html

In your browser.

lbineau commented 11 years ago

Thanks for quick reply. Unfortunatly the problem with setProperty still remains in IE

SCRIPT438: Object doesn't support property or method 'setProperty' 
jath.js, line 68 character 9 -> all IE versions

It's very weird because setProperty should work in IE. I tried to do a console.log of xmldoc in parseArray on IE : LOG: [object Document] so it is not a null or undefined object

Here is a screenshot with the qunit-test.html (with just the case-issue.js) image

1.Died on test #1: Object doesn't support property or method 'setProperty' - { "message": "Object doesn't support property or method 'setProperty'", "description": "Object doesn't support property or method 'setProperty'", "number": -2146827850, "name": "TypeError" }
lbineau commented 11 years ago

The patch works with real IE 7&8 (I've been testing it with IE9 et IE10 compatibility mode) But still doesn't work in IE9&10 maybe 'setProperty' is not supported by IE>=9 anymore ?

dnewcome commented 11 years ago

I have another machine with IE10 somewhere, I'll take a look in IE10.

dnewcome commented 11 years ago

I tested in IE10 and found that IE9 and IE10 are using a new DOMParser object instead of the traditional MSXML2 object. However their DOMParser is not API-compatible with a standards browser, despite having the same name. The new DOMParser doesn't support XPath at all, so there is no opportunity to add support directly for it. See:

http://stackoverflow.com/questions/13521554/xpath-in-internet-explorer-10-gone

However, legacy support for MSXML remains in IE9 and 10, so as long as you have an MSXML document Jath will work normally. I changed the test case subtly to create an MSXML-compatible document if you look at the changes I just checked in. For XMLHttpRequests you can do:

xhr.responseType = 'msxml-document';

Which should tell IE9/10 that you want the response to be an MSXML document rather than DOMParser.

See this post for more details:

http://blogs.msdn.com/b/ie/archive/2012/07/19/xmlhttprequest-responsexml-in-ie10-release-preview.aspx

In the future I'm thinking about replacing XPath in IE with this library:

http://code.google.com/p/wicked-good-xpath/

I was able to run the test in IE10. I don't have ready access to IE9, so let me know if it works for you.

lbineau commented 11 years ago

It seems to solve the problem in both case ! Maybe worth it to try this library ? http://code.google.com/p/wicked-good-xpath/ I'll be glad to help you in testing it.

dnewcome commented 11 years ago

Thanks for the offer, I'll probably do a rewrite when I get time using the wicked-good library. I'm looking into implementing this in C# also, so I'll probably do some research on updating this stuff soon.