I have a server delivering a data query in XML format. When the query fails or is ill-formed the server returns a 200 OK response that is a error message in the guise of an HTML page.
In IE the parse of the response fails, and in Chrome it does not.
The data.xml.js parse: method uses jQuery (I am using 1.7.1) $.parseXML which in turn uses
The Microsoft.XMLDOM parser does not like the HTML and its .LoadXML() returns a null.
So the question is should data.xml.js handle the HTML ? I would suggest no, or at least make it controllable through an option since some future task may require using data found in some xpath of an HTML response.
To fail the HTML response I made this adjustment in kendo.data.xml.js parse:
changed to
A schema: property could be used to control the strictness of parsing.
schema: { type: 'xml', strict: true, ... } // strict (default) requires <?xml lead-in, false allows for any lead-in
schema: { type: 'xml', leadin: '<?DOCTYPE HTML', ... } // string (or array of string) for specifying allowed lead-ins
Happy coding,
Richard
In IE the parse of the response fails, and in Chrome it does not.
The data.xml.js parse: method uses jQuery (I am using 1.7.1) $.parseXML which in turn uses
- window.DOMParser, or
- ActiveXObject( "Microsoft.XMLDOM" )
The Microsoft.XMLDOM parser does not like the HTML and its .LoadXML() returns a null.
So the question is should data.xml.js handle the HTML ? I would suggest no, or at least make it controllable through an option since some future task may require using data found in some xpath of an HTML response.
To fail the HTML response I made this adjustment in kendo.data.xml.js parse:
documentElement = xml.documentElement || $.parseXML(xml).documentElement;
changed to
documentElement
= xml.documentElement
|| ( xml.substr(0,5)==
'<?xml'
? $.parseXML(xml).documentElement
: jQuery.error(
"Invalid XML: "
+ xml )
)
;
A schema: property could be used to control the strictness of parsing.
schema: { type: 'xml', strict: true, ... } // strict (default) requires <?xml lead-in, false allows for any lead-in
schema: { type: 'xml', leadin: '<?DOCTYPE HTML', ... } // string (or array of string) for specifying allowed lead-ins
Happy coding,
Richard