]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/datatype/datatype-xml-parse.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / datatype / datatype-xml-parse.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('datatype-xml-parse', function(Y) {
9
10 /**
11  * Parse XML submodule.
12  *
13  * @module datatype
14  * @submodule datatype-xml-parse
15  * @for DataType.XML
16  */
17
18 var LANG = Y.Lang;
19
20 Y.mix(Y.namespace("DataType.XML"), {
21     /**
22      * Converts data to type XMLDocument.
23      *
24      * @method parse
25      * @param data {String} Data to convert.
26      * @return {XMLDoc} XML Document.
27      */
28     parse: function(data) {
29         var xmlDoc = null;
30         if(LANG.isString(data)) {
31             try {
32                 if(!LANG.isUndefined(ActiveXObject)) {
33                         xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
34                         xmlDoc.async = false;
35                         xmlDoc.loadXML(data);
36                 }
37             }
38             catch(ee) {
39                 try {
40                     if(!LANG.isUndefined(DOMParser)) {
41                         xmlDoc = new DOMParser().parseFromString(data, "text/xml");
42                     }
43                 }
44                 catch(e) {
45                 }
46             }
47         }
48         
49         if( (LANG.isNull(xmlDoc)) || (LANG.isNull(xmlDoc.documentElement)) || (xmlDoc.documentElement.nodeName === "parsererror") ) {
50         }
51         
52         return xmlDoc;
53     }
54 });
55
56 // Add Parsers shortcut
57 Y.namespace("Parsers").xml = Y.DataType.XML.parse;
58
59
60
61 }, '3.3.0' ,{requires:['yui-base']});