Skip to content

Commit

Permalink
XML: Refactor of feature detecting logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezequiel Rodriguez committed Nov 25, 2013
1 parent cc4eed2 commit 680a9e8
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions src/xml/js/xml-parse.js
Expand Up @@ -6,8 +6,6 @@
* @for XML
*/

var LANG = Y.Lang;

Y.mix(Y.namespace("XML"), {
/**
* Converts data to type XMLDocument.
Expand All @@ -17,32 +15,22 @@ Y.mix(Y.namespace("XML"), {
* @return {XMLDoc} XML Document.
*/
parse: function(data) {
var xmlDoc = null;
if(LANG.isString(data)) {
try {
if(!LANG.isUndefined(ActiveXObject)) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(data);
}
}
catch(ee) {
try {
if (!LANG.isUndefined(DOMParser)) {
xmlDoc = new DOMParser().parseFromString(data, "text/xml");
}
if (!LANG.isUndefined(Windows.Data.Xml.Dom)) {
xmlDoc = new Windows.Data.Xml.Dom.XmlDocument();
xmlDoc.loadXml(data);
}
}
catch(e) {
}
Y.log(ee.message + " (Could not initialize the ActiveX control for XML parsing)", "warn", "xml");
var xmlDoc = null, win;
if (typeof data === "string") {
win = Y.config.win;
if (win.DOMParser !== undefined) {
xmlDoc = new DOMParser().parseFromString(data, "text/xml");
} else if (win.ActiveXObject !== undefined) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(data);
} else if (win.Windows !== undefined) {
xmlDoc = new Windows.Data.Xml.Dom.XmlDocument();
xmlDoc.loadXml(data);
}
}

if( (LANG.isNull(xmlDoc)) || (LANG.isNull(xmlDoc.documentElement)) || (xmlDoc.documentElement.nodeName === "parsererror") ) {
if (xmlDoc === null || xmlDoc.documentElement === null || xmlDoc.documentElement.nodeName === "parsererror") {
Y.log("Could not parse data to type XML Document", "warn", "xml");
}

Expand Down

0 comments on commit 680a9e8

Please sign in to comment.