]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/datatype/datatype-xml-parse.js
Release 6.2.0beta4
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / datatype / datatype-xml-parse.js
1 /*
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
5 version: 3.0.0
6 build: 1549
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(DOMParser)) {
33                     xmlDoc = new DOMParser().parseFromString(data, "text/xml");
34                 }
35             }
36             catch(e) {
37                 try {
38                     if(!LANG.isUndefined(ActiveXObject)) {
39                             xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
40                             xmlDoc.async = false;
41                             xmlDoc.loadXML(data);
42                     }
43                 }
44                 catch(ee) {
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
62 }, '3.0.0' );