[2704] | 1 | ( function( ) |
---|
| 2 | { |
---|
| 3 | function _XML( ) |
---|
| 4 | { |
---|
| 5 | if ( typeof arguments[ 0 ] != 'string' || arguments[ 0 ].length < 1 ) |
---|
| 6 | return null; |
---|
| 7 | |
---|
| 8 | return new ( function ( ) |
---|
| 9 | { |
---|
| 10 | var _document = null; |
---|
| 11 | var _root = null; |
---|
| 12 | var j = null; |
---|
| 13 | var _xsl_file = null; |
---|
| 14 | |
---|
| 15 | function _append( ) |
---|
| 16 | { |
---|
| 17 | var a = null; |
---|
| 18 | if ( typeof arguments[ 0 ] == 'string' && ( arguments[ 0 ] = arguments[ 0 ].replace ( /^ +| +$/g,'' ) ) != '' ) |
---|
| 19 | a = j.appendChild( _document.createElement( arguments[ 0 ] ) ); |
---|
| 20 | |
---|
| 21 | if ( a ) |
---|
| 22 | { |
---|
| 23 | var i = null; |
---|
| 24 | if ( arguments[ 1 ] !== null && typeof arguments[ 1 ] == 'object' ) |
---|
| 25 | for ( attr in arguments[ 1 ] ) |
---|
| 26 | a.setAttribute( attr,arguments[ 1 ][ attr ] ); |
---|
| 27 | |
---|
| 28 | if ( typeof arguments[ 2 ] == 'string' && arguments[ 2 ].replace( /^ +| +$/g, '' ) != '' ) |
---|
| 29 | a.appendChild( _document.createTextNode( arguments[ 2 ] ) ); |
---|
| 30 | |
---|
| 31 | function g( ) |
---|
| 32 | { |
---|
| 33 | j = a; |
---|
| 34 | var _node = _append.apply( this, arguments ); |
---|
| 35 | j = _root; |
---|
| 36 | return _node; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | function _parse_node( ) |
---|
| 40 | { |
---|
| 41 | var b = null; |
---|
| 42 | if ( _xsl_file ) |
---|
| 43 | b = _xsl_file; |
---|
| 44 | |
---|
| 45 | if ( i ) |
---|
| 46 | _xsl_file = i; |
---|
| 47 | |
---|
| 48 | var d = _document; |
---|
| 49 | _document = a; |
---|
| 50 | |
---|
| 51 | var f = null; |
---|
| 52 | if ( _xsl_file ) |
---|
| 53 | f = _parse.apply( this, arguments ); |
---|
| 54 | |
---|
| 55 | if ( b ) |
---|
| 56 | { |
---|
| 57 | _xsl_file = b; |
---|
| 58 | b = null; |
---|
| 59 | } |
---|
| 60 | _document = d; |
---|
| 61 | return f |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | function _xsl( ) |
---|
| 65 | { |
---|
| 66 | if ( arguments[ 0 ] && typeof arguments[ 0 ] == 'string' ) |
---|
| 67 | i = arguments[ 0 ]; |
---|
| 68 | |
---|
| 69 | return this |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | if ( arguments[ 3 ] && arguments[ 3 ].constructor == Object ) |
---|
| 73 | { |
---|
| 74 | arguments[ 3 ].append = arguments[ 3 ].$ = g; |
---|
| 75 | arguments[ 3 ].serialize = _serialize; |
---|
| 76 | arguments[ 3 ].xsl = _xsl; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | return new ( function ( ) |
---|
| 80 | { |
---|
| 81 | this.append = this.$ = g; |
---|
| 82 | this.serialize = _serialize; |
---|
| 83 | this.xsl = _xsl; |
---|
| 84 | this.parse = _parse_node; |
---|
| 85 | } ); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | return null |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | function _xml( i ) |
---|
| 92 | { |
---|
| 93 | var g = null; |
---|
| 94 | if ( document.implementation && document.implementation.createDocument ) |
---|
| 95 | { |
---|
| 96 | XMLDocument.prototype.load = function ( b ) |
---|
| 97 | { |
---|
| 98 | var d = new XMLHttpRequest( ); |
---|
| 99 | d.open( 'GET', b, false ); |
---|
| 100 | d.setRequestHeader( 'Content-Type', 'text/xml' ); |
---|
| 101 | d.send( null ); |
---|
| 102 | var f = d.responseXML; |
---|
| 103 | if ( f ) |
---|
| 104 | { |
---|
| 105 | var a = this.importNode( f.documentElement, true ); |
---|
| 106 | with ( this ) |
---|
| 107 | { |
---|
| 108 | appendChild( a ); |
---|
| 109 | } |
---|
| 110 | return true |
---|
| 111 | } |
---|
| 112 | }; |
---|
| 113 | g = document.implementation.createDocument( '', '', null ); |
---|
| 114 | } |
---|
| 115 | else |
---|
| 116 | g = new ActiveXObject( 'Msxml2.FreeThreadedDOMDocument' ); |
---|
| 117 | |
---|
| 118 | g.async = false; |
---|
| 119 | g.load( i + ( ( i.indexOf( '?' ) < 0 ) ? '?' + Date.parse( new Date ) : '' ) ); |
---|
| 120 | |
---|
| 121 | return g; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | function _load( b ) |
---|
| 125 | { |
---|
| 126 | _document = _xml( b ); |
---|
| 127 | _root = j = _document.documentElement; |
---|
| 128 | return this; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | function _parse( ) |
---|
| 132 | { |
---|
| 133 | var _fragment = null; |
---|
| 134 | var _params = { }; |
---|
| 135 | |
---|
| 136 | if ( arguments[ 0 ] && arguments[ 0 ].constructor == Object ) |
---|
| 137 | for ( var _index in arguments[ 0 ] ) |
---|
| 138 | { |
---|
| 139 | var _type_index = _index.constructor; |
---|
| 140 | if ( _type_index != String && _type_index != Number ) |
---|
| 141 | continue; |
---|
| 142 | |
---|
| 143 | var _type_param = arguments[ 0 ][ _index ].constructor; |
---|
| 144 | if ( _type_param == Object || _type_param == Function ) |
---|
| 145 | continue; |
---|
| 146 | |
---|
| 147 | _params[ String( _index ) ] = String( arguments[ 0 ][ _index ] ); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | if ( window.XSLTProcessor ) |
---|
| 151 | { |
---|
| 152 | var _processor = new XSLTProcessor( ); |
---|
| 153 | _processor.importStylesheet( _xml( _xsl_file ) ); |
---|
| 154 | |
---|
| 155 | for ( var _param in _params ) |
---|
| 156 | if ( _params[ _param ].constructor == String ) |
---|
| 157 | _processor.setParameter( null, _param, _params[ _param ] ); |
---|
| 158 | |
---|
| 159 | _fragment = _processor.transformToFragment( _document, document ); |
---|
| 160 | |
---|
| 161 | var _aux = document.createElement( 'div' ); |
---|
| 162 | _aux.appendChild( _fragment ); |
---|
| 163 | |
---|
| 164 | _fragment = _aux.innerHTML |
---|
| 165 | } |
---|
| 166 | else |
---|
| 167 | { |
---|
| 168 | var _xsl_template = new ActiveXObject( 'MSXML2.XSLTemplate' ); |
---|
| 169 | _xsl_template.stylesheet = _xml( _xsl_file ); |
---|
| 170 | |
---|
| 171 | var _processor = _xsl_template.createProcessor( ); |
---|
| 172 | _processor.input = _xml( _xsl_file ); |
---|
| 173 | |
---|
| 174 | for ( var _param in _params ) |
---|
| 175 | if ( _params[ _param ].constructor == String ) |
---|
| 176 | _processor.addParameter( String( _param ), String( _params[ _param ] ), '' ); |
---|
| 177 | |
---|
| 178 | _processor.transform( ); |
---|
| 179 | _fragment = _processor.output; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | return _fragment; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | function _serialize( ) |
---|
| 186 | { |
---|
| 187 | try |
---|
| 188 | { |
---|
| 189 | return ( new XMLSerializer( ) ).serializeToString( _document ); |
---|
| 190 | } |
---|
| 191 | catch ( e ) |
---|
| 192 | { |
---|
| 193 | try |
---|
| 194 | { |
---|
| 195 | return _document.xml; |
---|
| 196 | } |
---|
| 197 | catch ( e ) |
---|
| 198 | { |
---|
| 199 | return null; |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | function _xsl( ) |
---|
| 205 | { |
---|
| 206 | if ( arguments[ 0 ] && typeof arguments[ 0 ] == 'string' ) |
---|
| 207 | _xsl_file = arguments[ 0 ]; |
---|
| 208 | |
---|
| 209 | return this; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | this.append = this.$ = _append; |
---|
| 213 | this.load = _load; |
---|
| 214 | this.serialize = _serialize; |
---|
| 215 | this.xsl = _xsl; |
---|
| 216 | this.parse = _parse; |
---|
| 217 | |
---|
| 218 | if ( document.implementation.createDocument ) |
---|
| 219 | _document = document.implementation.createDocument( '', '', null ); |
---|
| 220 | else |
---|
| 221 | if ( ActiveXObject ) |
---|
| 222 | _document = new ActiveXObject( 'Msxml2.DOMDocument' ); |
---|
| 223 | |
---|
| 224 | with ( _document ) |
---|
| 225 | appendChild( createProcessingInstruction( 'xml', 'version = "1.0" encoding = "UTF-8"' ) ); |
---|
| 226 | |
---|
| 227 | _root = _document.appendChild( _document.createElement( arguments[ 0 ] ) ); |
---|
| 228 | j = _root; |
---|
| 229 | |
---|
| 230 | function p( ) |
---|
| 231 | { |
---|
| 232 | for ( child in arguments[ 0 ] ) |
---|
| 233 | { |
---|
| 234 | var b = this.$( arguments[ 0 ][ child ].name, arguments[ 0 ][ child ].attributes, arguments[ 0 ][ child ].value ); |
---|
| 235 | if ( arguments[ 0 ][ child ].children && arguments[ 0 ][ child ].children.constructor == Array ) |
---|
| 236 | p.call( b, arguments[ 0 ][ child ].children ); |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | if ( arguments[ 1 ] && arguments[ 1 ].constructor == Array ) |
---|
| 241 | p.call( this, arguments[ 1 ] ) |
---|
| 242 | |
---|
| 243 | } )( arguments[ 0 ], arguments[ 1 ] ); |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | window.XML = _XML; |
---|
| 247 | } )( ); |
---|