1/* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * FCKXml Class: class to load and manipulate XML files. 22 */ 23 24FCKXml.prototype = 25{ 26 LoadUrl : function( urlToCall ) 27 { 28 this.Error = false ; 29 var oFCKXml = this ; 30 31 var oXmlHttp = FCKTools.CreateXmlObject( 'XmlHttp' ) ; 32 oXmlHttp.open( "GET", urlToCall, false ) ; 33 oXmlHttp.send( null ) ; 34 35 if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 ) 36 this.DOMDocument = oXmlHttp.responseXML ; 37 else if ( oXmlHttp.status == 0 && oXmlHttp.readyState == 4 ) 38 this.DOMDocument = oXmlHttp.responseXML ; 39 else 40 this.DOMDocument = null ; 41 42 if ( this.DOMDocument == null || this.DOMDocument.firstChild == null ) 43 { 44 this.Error = true ; 45 if (window.confirm( 'Error loading "' + urlToCall + '"\r\nDo you want to see more info?' ) ) 46 alert( 'URL requested: "' + urlToCall + '"\r\n' + 47 'Server response:\r\nStatus: ' + oXmlHttp.status + '\r\n' + 48 'Response text:\r\n' + oXmlHttp.responseText ) ; 49 50 } 51 }, 52 53 SelectNodes : function( xpath, contextNode ) 54 { 55 if ( this.Error ) 56 return new Array() ; 57 58 var aNodeArray = new Array(); 59 60 var xPathResult = this.DOMDocument.evaluate( xpath, contextNode ? contextNode : this.DOMDocument, 61 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ; 62 if ( xPathResult ) 63 { 64 var oNode = xPathResult.iterateNext() ; 65 while( oNode ) 66 { 67 aNodeArray[aNodeArray.length] = oNode ; 68 oNode = xPathResult.iterateNext(); 69 } 70 } 71 return aNodeArray ; 72 }, 73 74 SelectSingleNode : function( xpath, contextNode ) 75 { 76 if ( this.Error ) 77 return null ; 78 79 var xPathResult = this.DOMDocument.evaluate( xpath, contextNode ? contextNode : this.DOMDocument, 80 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null); 81 82 if ( xPathResult && xPathResult.singleNodeValue ) 83 return xPathResult.singleNodeValue ; 84 else 85 return null ; 86 } 87} ;