#2425 closed bug (invalid)
.text() and CDATA
Reported by: | john | Owned by: | john |
---|---|---|---|
Priority: | low | Milestone: | |
Component: | core | Version: | 1.4.3 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Currently accessing CDATA contents can be pretty annoying across platforms (IE is different from the rest. .text() should be made to handle these differences.
Change History (11)
comment:1 Changed 15 years ago by
comment:2 Changed 14 years ago by
I've just re-encountered this. For the curious my workaround is instead of using .text() to use this plugin I created (simply replace .text() with .getCDATA():
jQuery.fn.getCDATA = function() { if($.browser.msie) return this[0].childNodes[0].nodeValue; // Other browsers do this return this[0].childNodes[1].nodeValue; };
It ain't pretty, but in my case did the job.
comment:3 follow-up: 4 Changed 14 years ago by
Are you specifying the dataType in your ajax call? If specified as xml .text() should get you the node text within the CDATA; same goes for the .get method.
$.ajax({
type: "GET", url: "your.xml", dataType: "xml" success: your_function
});
comment:4 Changed 14 years ago by
I'm not specifying a type. The response from the server is application/xml, so jQuery should be treating it as such.
Per the docs:
The type of data that you're expecting back from the server. If none is specified, jQuery will intelligently pass either responseXML or responseText to your success callback, based on the MIME type of the response
Based on this, jQuery should correctly handle this.
Now I'm wondering if the bug is in jQuery's detection methods or in it's ability to parse CDATA.
comment:6 Changed 12 years ago by
Keywords: | needsreview added |
---|---|
Milestone: | 1.2.4 |
Owner: | set to john |
Status: | new → pending |
Thanks for taking the time to contribute to the jQuery project! Please provide a jsFiddle that outlines practical use cases for your enhancement request.
comment:7 Changed 12 years ago by
Keywords: | needsreview removed |
---|---|
Priority: | major → low |
comment:8 Changed 12 years ago by
Doesn't work for me.
When fetching XML, our server doesn't send the right mime-type,
- if I specify datatype, needs to be browser specific (FF, IE) : 'xml' or 'text/xml' get it the wrong way round => barfs
- neither way parses CDATA correctly...
- whichever datatype is specified, (or if I don't pass the datatype field) data is treated as HTML
- - which works fine... until a CDATA field (which is bad HTML)
Bug
- respect the datatype field, and make it cross browser (i.e. ignore server mime-type if datatype is set)
Workaround
- use datatype plain text
- then convert using "normal" JS
if ( window.DOMParser ) {var parser = new DOMParser(); xml = parser.parseFromString( data, "text/xml" );} else
{ xml = new ActiveXObject("Microsoft.XMLDOM"); xml.async = "false"; xml.loadXML( data ); }
Which leads to a: Feature Request
- add: xml_to_text() and text_to_xml()
comment:9 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | pending → closed |
Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!
comment:10 Changed 12 years ago by
Bug mentioned in comment #8 happened in version 1.4.3.
Still valid.
comment:11 Changed 12 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Version: | 1.2.3 → 1.4.3 |
I'd like to see a test case of this with the latest build of jquery
comment:12 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Please reopen/comment on this ticket only if you have a valid test case for the latest version of jQuery.
+1 there should be a crossbrowser solution