OSDN Git Service

38fcaf3cfbe284c911f9ccaae174920e378d79da
[pettanr/clientJs.git] / 0.6.x / js / 05_util / 04_XXML.js
1 /*\r
2  * XMLWrapper_find 周りの オリジナルコードに関する情報\r
3  *  Original code by pettanR team\r
4  *  - https://osdn.jp/projects/pettanr/scm/git/clientJs/blobs/master/0.6.x/js/02_dom/08_XNodeSelector.js\r
5  *  and\r
6  *  Original code by ofk ( kQuery, ksk )\r
7  *  - http://d.hatena.ne.jp/ofk/comment/20090106/1231258010\r
8  *  - http://d.hatena.ne.jp/ofk/20090111/1231668170\r
9  * \r
10  * TODO X.Class で作り、kill を強要する\r
11  */\r
12 \r
13 X[ 'XML' ] = XMLWrapper;\r
14 \r
15 /**\r
16  * XML 探索用のラッパークラスです\r
17  * @alias X.XML\r
18  * @class XML 探索用のラッパークラスです\r
19  * @constructor\r
20  * @param {xml}\r
21  */\r
22 function XMLWrapper( xml ){\r
23         this._rawXML = xml;\r
24 };\r
25 \r
26 XMLWrapper.prototype.length      = 1;\r
27 XMLWrapper.prototype[ 'parent' ] = XMLWrapper_parent;\r
28 XMLWrapper.prototype[ 'has' ]    = XMLWrapper_has;\r
29 XMLWrapper.prototype[ 'get' ]    = XMLWrapper_get;\r
30 XMLWrapper.prototype[ 'val' ]    = XMLWrapper_val;\r
31 XMLWrapper.prototype[ 'find' ]   = XMLWrapper_find;\r
32 \r
33 function XMLWrapper_parent(){\r
34         if( this.length === 1 ) return this._rawXML && this._rawXML.parentNode ? new XMLWrapper( this._rawXML.parentNode ) : null;\r
35         if( this.length === 0 ) return null;\r
36         \r
37         return this[ 0 ].parentNode ? ( new XMLWrapper( this[ 0 ].parentNode ) ) : null;\r
38 };\r
39 \r
40 function XMLWrapper_has( queryString ){\r
41         return !!this.find( queryString ).length;\r
42 };\r
43 \r
44 function XMLWrapper_get( index ){\r
45         if( this.length === 1 ) return this;\r
46         if( this.length === 0 ) return null;\r
47         // 一度発行した XMLWrapper は控えて置いて再発行する。\r
48         if( this._wraps && this._wraps[ index ] ) return this._wraps[ index ];\r
49         if( !this._wraps ) this._wraps = [];\r
50         return this[ index ] ?\r
51                 ( this._wraps[ index ] = new XMLWrapper( this[ index ] ) ) :\r
52                 null;\r
53 };\r
54 \r
55 function XMLWrapper_val( queryString, type ){\r
56         var //attr_textContent = X_UA[ 'IE' ] < 9 || X_UA[ 'Opera' ] ? 'innerText' : X_UA[ 'IE9' ] ? 'text' : 'textContent',\r
57                 wrapper, xml, v;\r
58         \r
59         switch( queryString ){\r
60                 case 'number' :\r
61                 case 'int' :\r
62                 case 'boolean' :\r
63                 case 'string' :\r
64                 case undefined :\r
65                         type = queryString;\r
66                         queryString = 0;\r
67         };\r
68                 \r
69         wrapper = queryString ? this.find( queryString ) : this;\r
70         xml     = wrapper.length === 1 ? wrapper._rawXML : wrapper[ 0 ];\r
71 \r
72         if( !xml ){\r
73                 switch( type ){\r
74                         case 'number' :\r
75                         case 'int' :\r
76                                 return NaN;\r
77                         case 'boolean' :\r
78                                 return false;\r
79                         case 'string' :\r
80                                 return '';\r
81                         default :\r
82                                 return null;\r
83                 };\r
84         };\r
85         \r
86         v = xml.nodeType === 1 ? xml.innerText || xml.text || xml.textContent : xml.nodeValue;\r
87         //xml.toStrign()\r
88         switch( type ){\r
89                 case 'number' :\r
90                         return parseFloat( v );\r
91                 case 'int' :\r
92                         return parseFloat( v ) | 0;\r
93                 case 'boolean' :\r
94                         return !!X_String_parse( v );\r
95                 //case 'string' :\r
96                 //default :     \r
97         };\r
98         return v || '';\r
99 };\r
100 \r
101         function XMLWrapper_find( queryString ){\r
102 \r
103                 var scope     = this.constructor === XMLListWrapper ? this : [ this._rawXML ],\r
104                         parents   = scope, // 探索元の親要素 xmlList の場合あり\r
105                         ARY_PUSH  = Array.prototype.push,\r
106                         ret       = [], // 結果要素\r
107                         isXML     = true,\r
108                         isMulti   = 1 < scope.length,// 要素をマージする必要がある\r
109                         isStart   = true,\r
110                         _         = ' ',\r
111                         isAll, isNot, hasRoot,\r
112                         l, i, n, parsed,\r
113                         xmlList, // 一時保存用\r
114                         merge, // 要素がコメントノードで汚染されている場合使う\r
115                         combinator, selector, name, tagName,\r
116                         uid, tmp, xml, filter, key, op, val, toLower, useName,\r
117             links, className, attr, flag;\r
118 \r
119                 // 文字列以外は空で返す\r
120                 if( !X_Type_isString( queryString ) ) return XMLListWrapper_0;\r
121                 \r
122                 xmlList = [];\r
123                 \r
124                 // 以下、パースと探索\r
125                 for( ; queryString.length; ){\r
126                         //console.log( 'queryString[' + queryString + ']' );\r
127                         \r
128                         // 初期化処理\r
129                         if( !parsed ){\r
130                                 parsed = X_Node_Selector__parse( queryString );\r
131                                 \r
132                                 if( X_Type_isNumber( parsed ) ){\r
133                                         // error\r
134                                         return XMLListWrapper_0;\r
135                                 };\r
136                                 \r
137                                 queryString = queryString.substr( parsed[ 0 ] );\r
138                                 parsed      = parsed[ 1 ];\r
139                                 \r
140                                 if( parsed === 5 ){\r
141                                         isMulti = true;\r
142                                         parents = scope;\r
143                                         xmlList && xmlList.length && ARY_PUSH.apply( ret, xmlList );\r
144                                         parsed  = null;\r
145                                         xmlList = [];\r
146                                         isStart = true;\r
147                                         continue;\r
148                                 };\r
149                         };\r
150                         \r
151                         combinator  = parsed[ 0 ];\r
152                         selector    = parsed[ 1 ];\r
153                         name        = parsed[ 2 ];\r
154                         tagName     = selector === 1 ? name : '*';\r
155                         isAll       = tagName === '*';\r
156         \r
157                         if( !isStart ){\r
158                                 if( !xmlList.length ){\r
159                                         parsed = null;\r
160                                         continue;                                       \r
161                                 } else\r
162                                 if( combinator !== 0 ){\r
163                                         parents = xmlList;\r
164                                         xmlList = [];\r
165                                         //console.log( 'cobinator !== 0 ' + parents.length + ' : ' + xmlList.length );\r
166                                 };\r
167                         };\r
168                         \r
169                         i = 0;\r
170                         l = parents.length;\r
171                         n = -1; \r
172                         isMulti = isMulti || 1 < l;\r
173                         \r
174                         console.log( 'combinator ' + combinator );\r
175         \r
176                         switch( combinator ){\r
177                                 // > TagName|*\r
178                                 case 2 :\r
179                                         for( ; i < l; ++i ){\r
180                                                 for( xml = parents[ i ].firstChild; xml; xml = xml.nextSibling ){\r
181                                                         if( xml.nodeType === 1 && ( isAll || tagName === xml.tagName ) ) xmlList[ ++n ] = xml;\r
182                                                 };                              \r
183                                         };\r
184                                         break;\r
185                                 // + TagName|*\r
186                                 case 3 :\r
187                                         for( ; i < l; ++i ){\r
188                                                 for( xml = parents[ i ].nextSibling; xml; xml = xml.nextSibling ){\r
189                                                         if( xml.nodeType === 1 ){\r
190                                                                 if( isAll || tagName === xml.tagName ) xmlList[ ++n ] = xml;\r
191                                                                 break;                                                          \r
192                                                         };\r
193                                                 };                                                              \r
194                                         };\r
195                                         break;\r
196                                 // ~ TagName|*\r
197                                 case 4 :\r
198                                         merge = [];\r
199                                         for( ; i < l; ++i ){\r
200                                                 for( xml = parents[ i ].nextSibling; xml; xml = xml.nextSibling ){\r
201                                                         if( xml.nodeType === 1 && ( isAll || tagName === xml.tagName ) ){\r
202                                                                 if( merge.indexOf( xml ) !== -1 ){\r
203                                                                         break;\r
204                                                                 } else {\r
205                                                                         merge[ merge.length ] = xml;\r
206                                                                         xmlList[ ++n ] = xml;\r
207                                                                 };\r
208                                                         };                                                                      \r
209                                                 };                                                              \r
210                                         };\r
211                                         break;\r
212 \r
213                                 // @ 属性ノード\r
214                                 case 6 :\r
215                                         selector = 0;\r
216                                         tagName  = '*';\r
217                                         for( ; i < l; ++i ){\r
218                                                 if( xml = parents[ i ].getAttributeNode( name ) ){\r
219                                                         xmlList[ ++n ] = xml;\r
220                                                 };\r
221                                         };\r
222                                         break;\r
223                                 default :\r
224                                         if( combinator === 1 || ( isStart && selector < 7 ) ){\r
225                                                 console.log( l + ' > ' + xmlList.length + ' tag:' + tagName );\r
226                                                 for( ; i < l; ++i ){\r
227                                                         xml = parents[ i ];\r
228                                                         xml.childNodes && xml.childNodes.length && XMLWrapper_fetchElements( xmlList, xml, isAll ? null : tagName );\r
229                                                 };\r
230                                                 console.log( l + ' >> ' + xmlList.length + ' tag:' + tagName );\r
231                                         };\r
232                         };\r
233                         \r
234                         isStart = false;\r
235                         \r
236                         //alert( 'pre-selector:' + ( xmlList && xmlList.length ) )\r
237                         \r
238                         switch( selector ){\r
239                                 // #, ID\r
240                                 case 2 :\r
241                                         filter = [ 'id', 1, name ]; break;\r
242                                 // ., class\r
243                                 case 3 :\r
244                                         filter = [ 'class', 3 /*'~='*/, name ]; break;\r
245                                 // :, 擬似クラス\r
246                                 case 4 :\r
247                                         if( !( filter = XMLWrapper_filter[ name ] ) ){\r
248                                                 return XMLListWrapper_0;;\r
249                                         };\r
250                                         break;\r
251                                 // [] 属性\r
252                                 case 5 :\r
253                                         filter = [ name, parsed[ 3 ], parsed[ 4 ] ]; break;\r
254                                 // :not\r
255                                 case 6 :\r
256                                         isNot  = true;\r
257                                         parsed = parsed[ 2 ];\r
258                                         name   = parsed[ 2 ];\r
259                                         switch( parsed[ 1 ] ) {\r
260                                                 case 1 :\r
261                                                         filter = [ 'tag', 1, name ]; break;\r
262                                                 // #, ID\r
263                                                 case 2 :\r
264                                                         filter = [ 'id', 1, name ]; break;\r
265                                                 // ., class\r
266                                                 case 3 :\r
267                                                         filter = [ 'class', 3, name ]; break;\r
268                                                 // :, 擬似クラス\r
269                                                 case 4 :\r
270                                                         if( !( filter = X_Node_Selector__filter[ name ] ) ){\r
271                                                                 return [];\r
272                                                         };\r
273                                                         break;\r
274                                                 // [] 属性\r
275                                                 case 5 :\r
276                                                         filter = [ name, parsed[ 3 ], parsed[ 4 ] ]; break;\r
277                                         };\r
278                                         break;\r
279                                 // scope\r
280                                 case 7 :\r
281                                         xmlList = scope; break;\r
282                                 /* root\r
283                                 case 8 :\r
284                                         hasRoot = true;\r
285                                         xmlList = [ HTML ]; break;\r
286                                 // link\r
287                                 case 9 :\r
288                                         if( links = document.links ){\r
289                                                 for( xmlList = [], i = links.length; i; ){\r
290                                                         xmlList[ --i ] = new Node( links[ i ] );\r
291                                                 };\r
292                                         } else {\r
293                                                 // area[href],a[href]\r
294                                         }; */\r
295                         };\r
296                         \r
297                         if( filter && xmlList.length ){\r
298                                 // filter.mが関数の場合\r
299                                 if( filter.m ){\r
300                                         xmlList = filter.m(\r
301                                                 {\r
302                                                         not : isNot,\r
303                                                         xml : isXML\r
304                                                 },\r
305                                                 xmlList,\r
306                                                 parsed[ 3 ], parsed[ 4 ]\r
307                                         );\r
308                                 } else\r
309                                 // filterが関数の場合\r
310                                 if( X_Type_isFunction( filter ) ){\r
311                                         tmp = [];\r
312                                         for( i = 0, n = -1; xml = xmlList[ i ]; ++i ){\r
313                                                 if( ( !!filter( xml ) ) ^ isNot ) tmp[ ++n ] = xml;     \r
314                                         };\r
315                                         xmlList = tmp;\r
316                                 } else {\r
317                                 // 属性セレクター                        \r
318                                         tmp = [];\r
319                                         key = filter[ 0 ];\r
320                                         op  = filter[ 1 ];\r
321                                         val = filter[ 2 ];\r
322 \r
323                                         // 通常\r
324                                                 if( op === 3 ) val = _ + val + _;\r
325 \r
326                                                 for( i = 0, n = -1, l = xmlList.length; i < l; ++i ){\r
327                                                         xml  = xmlList[ i ];\r
328                                                         attr = xml.getAttribute( key, 2 );\r
329                                                         flag = attr != null;// && ( !useName || attr !== '' );\r
330                                                         if( flag && op ){\r
331                                                                 //if( toLower ) attr = attr.toLowerCase();\r
332                                                                 \r
333                                                                 switch( op ){\r
334                                                                         case 1: // =\r
335                                                                                 flag = attr === val;\r
336                                                                                 break;\r
337                                                                         case 2: // !=\r
338                                                                                 flag = attr !== val;\r
339                                                                                 break;\r
340                                                                         case 3: // ~=\r
341                                                                                 flag = ( _ + attr + _ ).indexOf( val ) !== -1;\r
342                                                                                 break;\r
343                                                                         case 4: // ^=\r
344                                                                                 flag = attr.indexOf( val ) === 0;\r
345                                                                                 break;\r
346                                                                         case 5: // $=\r
347                                                                                 flag = attr.lastIndexOf( val ) + val.length === attr.length;\r
348                                                                                 break;\r
349                                                                         case 6: // *=\r
350                                                                                 flag = attr.indexOf( val ) !== -1;\r
351                                                                                 break;\r
352                                                                         case 7: // |=\r
353                                                                                 flag = attr === val || attr.substring( 0, val.length + 1 ) === val + '-';\r
354                                                                                 break;\r
355                                                                 };\r
356                                                         };\r
357                                                         if( !!flag ^ isNot ) tmp[ ++n ] = xml;\r
358                                                 //};\r
359                                         };\r
360                                         xmlList = tmp;\r
361                                 };\r
362                         };\r
363                         filter  = null;\r
364                         isNot   = false;\r
365                         parsed  = null;\r
366                         \r
367                         //console.log( '//end :' + ( xmlList && xmlList.length ) );\r
368                 };\r
369                 //console.log( 'multi:' + ( xmlList && xmlList.length ) );\r
370                 \r
371                 // tree 順に並び替え、同一要素の排除\r
372                 if( isMulti ){\r
373                         xmlList && xmlList.length && ARY_PUSH.apply( ret, xmlList );\r
374                         l = ret.length;\r
375                         if( l === 0 ) return XMLListWrapper_0;\r
376                         if( l === 1 ) return new XMLWrapper( ret[ 0 ] );\r
377                         \r
378                         xmlList = [];\r
379                         //merge   = [];\r
380                         for( i = 0, n = -1; i < l; ++i ){\r
381                                 //alert( 'multi:' + i )\r
382                                 xml = ret[ i ];\r
383                                 if( xmlList.indexOf( xml ) === -1 ){\r
384                                         //merge[ merge.length ] = xml;\r
385                                         xmlList[ ++n ] = xml;\r
386                                 };\r
387                         };\r
388                         XMLWrapper_sortElementOrder( ret = [], xmlList, this._rawXML.childNodes );\r
389                         \r
390                         // @\r
391                         for( i = 0, l = xmlList.length; i < l; ++i ){\r
392                                 if( ret.indexOf( xml = xmlList[ i ] ) === -1 ){\r
393                                         ret[ ret.length ] = xml;\r
394                                 };\r
395                         };\r
396                         \r
397                         xmlList = ret;\r
398                 };\r
399 \r
400                 return xmlList.length === 1 ? new XMLWrapper( xmlList[ 0 ] ) : new XMLListWrapper( xmlList );\r
401         };\r
402 \r
403         function XMLWrapper_sortElementOrder( newList, list, xmlList ){\r
404                 var l = xmlList.length,\r
405                         i = 0,\r
406                         j, child, _xmlList;\r
407                 for( ; i < l; ++i ){\r
408                         child = xmlList[ i ];\r
409                         //if( child.nodeType !== 1 ) continue;\r
410                         //console.log( child.tagName );\r
411                         if( ( j = list.indexOf( child ) ) !== -1 ){\r
412                                 newList[ newList.length ] = child;\r
413                                 list.splice( j, 1 );\r
414                                 if( list.length === 1 ){\r
415                                         newList[ newList.length ] = list[ 0 ];\r
416                                         list.length = 0;\r
417                                         return true;\r
418                                 };\r
419                                 if( list.length === 0 ) return true;\r
420                         };\r
421                         if( ( _xmlList = child.childNodes ) && XMLWrapper_sortElementOrder( newList, list, _xmlList ) ){\r
422                                 return true;\r
423                         };\r
424                 };\r
425         };\r
426         \r
427         function XMLWrapper_fetchElements( list, parent, tag ){\r
428                 var xmlList = parent.childNodes,\r
429                         l      = xmlList.length,\r
430                         i      = 0,\r
431                         child;\r
432                 for( ; i < l; ++i ){\r
433                         child = xmlList[ i ];\r
434                         if( child.nodeType === 1 ){\r
435                                 ( !tag || child.tagName === tag ) && ( list[ list.length ] = child );\r
436                                 //console.log( parent.tagName + ' > ' + child.tagName + ' == ' + tag+ ' l:' + list.length );\r
437                                 child.childNodes && child.childNodes.length && XMLWrapper_fetchElements( list, child, tag );\r
438                         };\r
439                 };\r
440         };\r
441 \r
442         function XMLWrapper_funcSelectorChild( type, flag_all, flags, xmlList ){\r
443                 var res      = [],\r
444                         flag_not = flags.not,\r
445                         i = 0, n = -1, xnode, node,\r
446                         tagName, tmp;\r
447                 for( ; xnode = xmlList[ i ]; ++i ){\r
448                         tagName = flag_all || xnode.tagName;\r
449                         tmp     = null;\r
450                         if( /* tmp === null && */ type <= 0 ){\r
451                                 for( node = xnode.previousSibling; node; node = node.previousSibling ){\r
452                                         if( node.nodeType === 1 && ( flag_all || tagName === node.tagName ) ){\r
453                                                 tmp = false;\r
454                                                 break;\r
455                                         };\r
456                                 };\r
457                         };\r
458                         if( tmp === null && 0 <= type ){\r
459                                 for( node = xnode.nextSibling; node; node = node.nextSibling ){\r
460                                         if( node.nodeType === 1 && ( flag_all || tagName === node.tagName ) ){\r
461                                                 tmp = false;\r
462                                                 break;\r
463                                         };              \r
464                                 };                                              \r
465                         };\r
466                         if( tmp === null ) tmp = true;\r
467                         if( tmp ^ flag_not ) res[ ++n ] = xnode;\r
468                 };\r
469                 return res;\r
470         };\r
471         function XMLWrapper_funcSelectorNth( pointer, sibling, flag_all, flags, xmlList, a, b ){\r
472                 var res      = [],\r
473                         checked  = {},\r
474                         flag_not = flags.not,\r
475                         i = 0, n = -1, uid,\r
476                         c, xnode, tmp, node, tagName;\r
477                 for( ; xnode = xmlList[ i ]; ++i ){\r
478                         uid = xnode._uid;\r
479                         tmp = checked[ uid ];\r
480                         if( tmp === undefined ){\r
481                                 for( c = 0, node = xnode.parentNode[ pointer ], tagName = flag_all || xnode.tagName; node; node = node[ sibling ] ){\r
482                                         if( node.nodeType === 1 && ( flag_all || tagName === node.tagName ) ){\r
483                                                 ++c;\r
484                                                 checked[ node._uid ] = a === 0 ? c === b : (c - b) % a === 0 && (c - b) / a >= 0;\r
485                                         };                                                      \r
486                                 };\r
487                                 tmp = checked[ uid ];\r
488                         };\r
489                         if( tmp ^ flag_not ) res[ ++n ] = xnode;\r
490                 };\r
491                 return res;\r
492         };\r
493         /*\r
494         function XMLWrapper_funcSelectorProp( prop, flag, flags, xmlList ){\r
495                 var res = [],\r
496                         flag_not = flag ? flags.not : !flags.not,\r
497                         i = 0, n = -1, xnode;\r
498                 for( ; xnode = xmlList[ i ]; ++i ){\r
499                         if( xnode.getAttributeNode( prop ) ^ flag_not ) res[ ++n ] = xnode;\r
500                 };\r
501                 return res;\r
502         }; */\r
503 \r
504 var XMLWrapper_filter = {\r
505         'first-child' : {\r
506                 m : function( flags, xmlList ){ return XMLWrapper_funcSelectorChild( -1, true, flags, xmlList ); }\r
507         },\r
508         'last-child' : {\r
509                 m : function( flags, xmlList ){ return XMLWrapper_funcSelectorChild( 1, true, flags, xmlList ); }\r
510         },\r
511         'only-child' : {\r
512                 m : function( flags, xmlList ){ return XMLWrapper_funcSelectorChild( 0, true, flags, xmlList ); }\r
513         },\r
514         'first-of-type' : {\r
515                 m : function( flags, xmlList ){ return XMLWrapper_funcSelectorChild( -1, false, flags, xmlList ); }\r
516         },\r
517         'last-of-type' : {\r
518                 m : function( flags, xmlList ){ return XMLWrapper_funcSelectorChild( 1, false, flags, xmlList ); }\r
519         },\r
520         'only-of-type' : {\r
521                 m : function( flags, xmlList ){ return XMLWrapper_funcSelectorChild( 0, false, flags, xmlList ); }\r
522         },\r
523         'nth-child' : {\r
524                 m : function( flags, xmlList, a, b ){ return XMLWrapper_funcSelectorNth( 'firstChild', 'nextSibling', true, flags, xmlList, a, b ); }\r
525         },\r
526         'nth-last-child' : {\r
527                 m : function( flags, xmlList, a, b ){ return XMLWrapper_funcSelectorNth( 'lastChild', 'previousSibling', true, flags, xmlList, a, b ); }\r
528         },\r
529         'nth-of-type' : {\r
530                 m : function( flags, xmlList, a, b ){ return XMLWrapper_funcSelectorNth( 'firstChild', 'nextSibling', false, flags, xmlList, a, b ); }\r
531         },\r
532         'nth-last-of-type' : {\r
533                 m : function( flags, xmlList, a, b ){ return XMLWrapper_funcSelectorNth( 'lastChild', 'previousSibling', false, flags, xmlList, a, b ); }\r
534         },\r
535         'empty' : {\r
536                 m : function( flags, xmlList ){\r
537                         var res = [],\r
538                                 flag_not = flags.not,\r
539                                 i = 0, n = -1, xnode, tmp, node;\r
540                         for( ; xnode = xmlList[i]; ++i ){\r
541                                 tmp = true;\r
542                                 for( node = xnode.firstChild; node; node = node.nextSibling ){\r
543                                         if( node.nodeType === 1 || ( node.nodeType === 3 && node.nodeValue ) ){\r
544                                                 tmp = false;\r
545                                                 break;\r
546                                         };                              \r
547                                 };\r
548                                 if( tmp ^ flag_not ) res[ ++n ] = xnode;\r
549                         };\r
550                         return res;\r
551                 }\r
552         },\r
553         'contains' : {\r
554                 m : function( flags, xmlList, arg ){\r
555                         var res = [],\r
556                                 flag_not = flags.not,\r
557                                 i = 0, n = -1, xnode, text = '';\r
558 \r
559                         for( ; xnode = xmlList[ i ]; ++i ){\r
560                                 switch( xnode.nodeType ){\r
561                                         case 1 :\r
562                                                 text = xml.nodeType === 1 ? xml.innerText || xml.text || xml.textContent : xml.nodeValue;\r
563                                                 break;\r
564                                         //case 2 :\r
565                                         case 3 :\r
566                                                 text = xnode.nodeValue;\r
567                                                 break;\r
568                                 };\r
569                                 console.log( text + ' ' + arg );\r
570                                 if ( ( -1 < text.indexOf( arg ) ) ^ flag_not ) res[ ++n ] = xnode;                                              \r
571                         };\r
572                         return res;\r
573                 }\r
574         }\r
575 };\r
576 \r
577 function XMLListWrapper( xmlList ){\r
578         var i = 0, l = xmlList ? xmlList.length : 0;\r
579         for( ; i < l; ++i ){\r
580                 this[ i ] = xmlList[ i ];\r
581         };\r
582         this.length = l;\r
583 };\r
584 \r
585 var XMLListWrapper_0 = new XMLListWrapper();\r
586 \r
587 XMLListWrapper.prototype.length      = 0;\r
588 XMLListWrapper.prototype._wraps      = null;\r
589 XMLListWrapper.prototype[ 'parent' ] = XMLWrapper_parent;\r
590 XMLListWrapper.prototype[ 'has' ]    = XMLWrapper_has;\r
591 XMLListWrapper.prototype[ 'get' ]    = XMLWrapper_get;\r
592 XMLListWrapper.prototype[ 'val' ]    = XMLWrapper_val;\r
593 XMLListWrapper.prototype[ 'find' ]   = XMLWrapper_find;\r