annotate Earth_x/jkl-parsexml.js @ 1:fccccbcc94be

xml_file_read
author e085737@tamayose-syuuichi-no-macbook.local
date Mon, 08 Nov 2010 16:14:24 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
1 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
2 // jkl-parsexml.js ---- JavaScript Kantan Library for Parsing XML
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
3 // Copyright 2005-2007 Kawasaki Yusuke <u-suke@kawa.net>
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
4 // http://www.kawa.net/works/js/jkl/parsexml.html
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
5 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
6 // v0.01 2005/05/18 first release
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
7 // v0.02 2005/05/20 Opera 8.0beta may be abailable but somtimes crashed
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
8 // v0.03 2005/05/20 overrideMimeType( "text/xml" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
9 // v0.04 2005/05/21 class variables: REQUEST_TYPE, RESPONSE_TYPE
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
10 // v0.05 2005/05/22 use Msxml2.DOMDocument.5.0 for GET method on IE6
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
11 // v0.06 2005/05/22 CDATA_SECTION_NODE
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
12 // v0.07 2005/05/23 use Microsoft.XMLDOM for GET method on IE6
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
13 // v0.10 2005/10/11 new function: JKL.ParseXML.HTTP.responseText()
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
14 // v0.11 2005/10/13 new sub class: JKL.ParseXML.Text, JSON and DOM.
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
15 // v0.12 2005/10/14 new sub class: JKL.ParseXML.CSV and CSVmap.
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
16 // v0.13 2005/10/28 bug fixed: TEXT_NODE regexp for white spaces
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
17 // v0.14 2005/11/06 bug fixed: TEXT_NODE regexp at Safari
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
18 // v0.15 2005/11/08 bug fixed: JKL.ParseXML.CSV.async() method
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
19 // v0.16 2005/11/15 new sub class: LoadVars, and UTF-8 text on Safari
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
20 // v0.18 2005/11/16 improve: UTF-8 text file on Safari
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
21 // v0.19 2006/02/03 use XMLHTTPRequest instead of ActiveX on IE7,iCab
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
22 // v0.20 2006/03/22 (skipped)
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
23 // v0.21 2006/11/30 use ActiveX again on IE7
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
24 // v0.22 2007/01/04 JKL.ParseXML.JSON.parseResponse() updated
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
25 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
26
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
27 if ( typeof(JKL) == 'undefined' ) JKL = function() {};
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
28
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
29 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
30 // class: JKL.ParseXML
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
31
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
32 JKL.ParseXML = function ( url, query, method ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
33 // debug.print( "new JKL.ParseXML( '"+url+"', '"+query+"', '"+method+"' );" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
34 this.http = new JKL.ParseXML.HTTP( url, query, method, false );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
35 return this;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
36 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
37
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
38 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
39 // class variables
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
40
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
41 JKL.ParseXML.VERSION = "0.22";
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
42 JKL.ParseXML.MIME_TYPE_XML = "text/xml";
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
43 JKL.ParseXML.MAP_NODETYPE = [
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
44 "",
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
45 "ELEMENT_NODE", // 1
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
46 "ATTRIBUTE_NODE", // 2
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
47 "TEXT_NODE", // 3
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
48 "CDATA_SECTION_NODE", // 4
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
49 "ENTITY_REFERENCE_NODE", // 5
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
50 "ENTITY_NODE", // 6
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
51 "PROCESSING_INSTRUCTION_NODE", // 7
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
52 "COMMENT_NODE", // 8
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
53 "DOCUMENT_NODE", // 9
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
54 "DOCUMENT_TYPE_NODE", // 10
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
55 "DOCUMENT_FRAGMENT_NODE", // 11
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
56 "NOTATION_NODE" // 12
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
57 ];
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
58
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
59 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
60 // define callback function (ajax)
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
61
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
62 JKL.ParseXML.prototype.async = function ( func, args ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
63 this.callback_func = func; // callback function
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
64 this.callback_arg = args; // first argument
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
65 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
66
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
67 JKL.ParseXML.prototype.onerror = function ( func, args ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
68 this.onerror_func = func; // callback function
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
69 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
70
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
71 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
72 // method: parse()
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
73 // return: parsed object
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
74 // Download a file from remote server and parse it.
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
75
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
76 JKL.ParseXML.prototype.parse = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
77 if ( ! this.http ) return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
78
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
79 // set onerror call back
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
80 if ( this.onerror_func ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
81 this.http.onerror( this.onerror_func );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
82 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
83
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
84 if ( this.callback_func ) { // async mode
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
85 var copy = this;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
86 var proc = function() {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
87 if ( ! copy.http ) return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
88 var data = copy.parseResponse();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
89 copy.callback_func( data, copy.callback_arg ); // call back
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
90 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
91 this.http.async( proc );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
92 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
93
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
94 this.http.load();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
95
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
96 if ( ! this.callback_func ) { // sync mode
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
97 var data = this.parseResponse();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
98 return data;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
99 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
100 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
101
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
102 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
103 // every child/children into array
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
104 JKL.ParseXML.prototype.setOutputArrayAll = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
105 this.setOutputArray( true );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
106 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
107 // a child into scalar, children into array
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
108 JKL.ParseXML.prototype.setOutputArrayAuto = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
109 this.setOutputArray( null );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
110 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
111 // every child/children into scalar (first sibiling only)
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
112 JKL.ParseXML.prototype.setOutputArrayNever = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
113 this.setOutputArray( false );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
114 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
115 // specified child/children into array, other child/children into scalar
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
116 JKL.ParseXML.prototype.setOutputArrayElements = function ( list ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
117 this.setOutputArray( list );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
118 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
119 // specify how to treate child/children into scalar/array
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
120 JKL.ParseXML.prototype.setOutputArray = function ( mode ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
121 if ( typeof(mode) == "string" ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
122 mode = [ mode ]; // string into array
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
123 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
124 if ( mode && typeof(mode) == "object" ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
125 if ( mode.length < 0 ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
126 mode = false; // false when array == []
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
127 } else {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
128 var hash = {};
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
129 for( var i=0; i<mode.length; i++ ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
130 hash[mode[i]] = true;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
131 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
132 mode = hash; // array into hashed array
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
133 if ( mode["*"] ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
134 mode = true; // true when includes "*"
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
135 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
136 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
137 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
138 this.usearray = mode;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
139 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
140
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
141 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
142 // method: parseResponse()
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
143
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
144 JKL.ParseXML.prototype.parseResponse = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
145 var root = this.http.documentElement();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
146 var data = this.parseDocument( root );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
147 return data;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
148 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
149
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
150 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
151 // convert from DOM root node to JavaScript Object
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
152 // method: parseElement( rootElement )
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
153
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
154 JKL.ParseXML.prototype.parseDocument = function ( root ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
155 // debug.print( "parseDocument: "+root );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
156 if ( ! root ) return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
157
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
158 var ret = this.parseElement( root ); // parse root node
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
159 // debug.print( "parsed: "+ret );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
160
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
161 if ( this.usearray == true ) { // always into array
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
162 ret = [ ret ];
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
163 } else if ( this.usearray == false ) { // always into scalar
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
164 //
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
165 } else if ( this.usearray == null ) { // automatic
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
166 //
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
167 } else if ( this.usearray[root.nodeName] ) { // specified tag
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
168 ret = [ ret ];
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
169 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
170
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
171 var json = {};
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
172 json[root.nodeName] = ret; // root nodeName
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
173 return json;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
174 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
175
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
176 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
177 // convert from DOM Element to JavaScript Object
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
178 // method: parseElement( element )
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
179
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
180 JKL.ParseXML.prototype.parseElement = function ( elem ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
181 // debug.print( "nodeType: "+JKL.ParseXML.MAP_NODETYPE[elem.nodeType]+" <"+elem.nodeName+">" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
182
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
183 // COMMENT_NODE
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
184
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
185 if ( elem.nodeType == 7 ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
186 return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
187 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
188
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
189 // TEXT_NODE CDATA_SECTION_NODE
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
190
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
191 if ( elem.nodeType == 3 || elem.nodeType == 4 ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
192 // var bool = elem.nodeValue.match( /[^\u0000-\u0020]/ );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
193 var bool = elem.nodeValue.match( /[^\x00-\x20]/ ); // for Safari
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
194 if ( bool == null ) return; // ignore white spaces
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
195 // debug.print( "TEXT_NODE: "+elem.nodeValue.length+ " "+bool );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
196 return elem.nodeValue;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
197 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
198
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
199 var retval;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
200 var cnt = {};
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
201
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
202 // parse attributes
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
203
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
204 if ( elem.attributes && elem.attributes.length ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
205 retval = {};
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
206 for ( var i=0; i<elem.attributes.length; i++ ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
207 var key = elem.attributes[i].nodeName;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
208 if ( typeof(key) != "string" ) continue;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
209 var val = elem.attributes[i].nodeValue;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
210 if ( ! val ) continue;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
211 if ( typeof(cnt[key]) == "undefined" ) cnt[key] = 0;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
212 cnt[key] ++;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
213 this.addNode( retval, key, cnt[key], val );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
214 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
215 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
216
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
217 // parse child nodes (recursive)
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
218
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
219 if ( elem.childNodes && elem.childNodes.length ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
220 var textonly = true;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
221 if ( retval ) textonly = false; // some attributes exists
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
222 for ( var i=0; i<elem.childNodes.length && textonly; i++ ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
223 var ntype = elem.childNodes[i].nodeType;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
224 if ( ntype == 3 || ntype == 4 ) continue;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
225 textonly = false;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
226 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
227 if ( textonly ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
228 if ( ! retval ) retval = "";
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
229 for ( var i=0; i<elem.childNodes.length; i++ ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
230 retval += elem.childNodes[i].nodeValue;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
231 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
232 } else {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
233 if ( ! retval ) retval = {};
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
234 for ( var i=0; i<elem.childNodes.length; i++ ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
235 var key = elem.childNodes[i].nodeName;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
236 if ( typeof(key) != "string" ) continue;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
237 var val = this.parseElement( elem.childNodes[i] );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
238 if ( ! val ) continue;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
239 if ( typeof(cnt[key]) == "undefined" ) cnt[key] = 0;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
240 cnt[key] ++;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
241 this.addNode( retval, key, cnt[key], val );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
242 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
243 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
244 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
245 return retval;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
246 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
247
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
248 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
249 // method: addNode( hash, key, count, value )
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
250
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
251 JKL.ParseXML.prototype.addNode = function ( hash, key, cnts, val ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
252 if ( this.usearray == true ) { // into array
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
253 if ( cnts == 1 ) hash[key] = [];
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
254 hash[key][hash[key].length] = val; // push
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
255 } else if ( this.usearray == false ) { // into scalar
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
256 if ( cnts == 1 ) hash[key] = val; // only 1st sibling
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
257 } else if ( this.usearray == null ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
258 if ( cnts == 1 ) { // 1st sibling
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
259 hash[key] = val;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
260 } else if ( cnts == 2 ) { // 2nd sibling
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
261 hash[key] = [ hash[key], val ];
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
262 } else { // 3rd sibling and more
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
263 hash[key][hash[key].length] = val;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
264 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
265 } else if ( this.usearray[key] ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
266 if ( cnts == 1 ) hash[key] = [];
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
267 hash[key][hash[key].length] = val; // push
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
268 } else {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
269 if ( cnts == 1 ) hash[key] = val; // only 1st sibling
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
270 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
271 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
272
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
273 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
274 // class: JKL.ParseXML.Text
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
275
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
276 JKL.ParseXML.Text = function ( url, query, method ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
277 // debug.print( "new JKL.ParseXML.Text( '"+url+"', '"+query+"', '"+method+"' );" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
278 this.http = new JKL.ParseXML.HTTP( url, query, method, true );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
279 return this;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
280 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
281
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
282 JKL.ParseXML.Text.prototype.parse = JKL.ParseXML.prototype.parse;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
283 JKL.ParseXML.Text.prototype.async = JKL.ParseXML.prototype.async;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
284 JKL.ParseXML.Text.prototype.onerror = JKL.ParseXML.prototype.onerror;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
285
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
286 JKL.ParseXML.Text.prototype.parseResponse = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
287 var data = this.http.responseText();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
288 return data;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
289 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
290
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
291 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
292 // class: JKL.ParseXML.JSON
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
293
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
294 JKL.ParseXML.JSON = function ( url, query, method ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
295 // debug.print( "new JKL.ParseXML.JSON( '"+url+"', '"+query+"', '"+method+"' );" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
296 this.http = new JKL.ParseXML.HTTP( url, query, method, true );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
297 return this;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
298 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
299
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
300 JKL.ParseXML.JSON.prototype.parse = JKL.ParseXML.prototype.parse;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
301 JKL.ParseXML.JSON.prototype.async = JKL.ParseXML.prototype.async;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
302 JKL.ParseXML.JSON.prototype.onerror = JKL.ParseXML.prototype.onerror;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
303
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
304 JKL.ParseXML.JSON.prototype.parseResponse = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
305 var text = this.http.responseText();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
306 // http://www.antimon2.atnifty.com/2007/01/jklparsexmljson.html
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
307 if ( typeof(text) == 'undefined' ) return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
308 if ( ! text.length ) return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
309 var data = eval( "("+text+")" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
310 return data;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
311 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
312
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
313 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
314 // class: JKL.ParseXML.DOM
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
315
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
316 JKL.ParseXML.DOM = function ( url, query, method ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
317 // debug.print( "new JKL.ParseXML.DOM( '"+url+"', '"+query+"', '"+method+"' );" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
318 this.http = new JKL.ParseXML.HTTP( url, query, method, false );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
319 return this;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
320 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
321
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
322 JKL.ParseXML.DOM.prototype.parse = JKL.ParseXML.prototype.parse;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
323 JKL.ParseXML.DOM.prototype.async = JKL.ParseXML.prototype.async;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
324 JKL.ParseXML.DOM.prototype.onerror = JKL.ParseXML.prototype.onerror;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
325
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
326 JKL.ParseXML.DOM.prototype.parseResponse = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
327 var data = this.http.documentElement();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
328 return data;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
329 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
330
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
331 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
332 // class: JKL.ParseXML.CSV
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
333
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
334 JKL.ParseXML.CSV = function ( url, query, method ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
335 // debug.print( "new JKL.ParseXML.CSV( '"+url+"', '"+query+"', '"+method+"' );" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
336 this.http = new JKL.ParseXML.HTTP( url, query, method, true );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
337 return this;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
338 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
339
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
340 JKL.ParseXML.CSV.prototype.parse = JKL.ParseXML.prototype.parse;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
341 JKL.ParseXML.CSV.prototype.async = JKL.ParseXML.prototype.async;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
342 JKL.ParseXML.CSV.prototype.onerror = JKL.ParseXML.prototype.onerror;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
343
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
344 JKL.ParseXML.CSV.prototype.parseResponse = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
345 var text = this.http.responseText();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
346 var data = this.parseCSV( text );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
347 return data;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
348 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
349
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
350 JKL.ParseXML.CSV.prototype.parseCSV = function ( text ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
351 text = text.replace( /\r\n?/g, "\n" ); // new line character
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
352 var pos = 0;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
353 var len = text.length;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
354 var table = [];
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
355 while( pos<len ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
356 var line = [];
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
357 while( pos<len ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
358 if ( text.charAt(pos) == '"' ) { // "..." quoted column
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
359 var nextquote = text.indexOf( '"', pos+1 );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
360 while ( nextquote<len && nextquote > -1 ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
361 if ( text.charAt(nextquote+1) != '"' ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
362 break; // end of column
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
363 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
364 nextquote = text.indexOf( '"', nextquote+2 );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
365 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
366 if ( nextquote < 0 ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
367 // unclosed quote
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
368 } else if ( text.charAt(nextquote+1) == "," ) { // end of column
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
369 var quoted = text.substr( pos+1, nextquote-pos-1 );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
370 quoted = quoted.replace(/""/g,'"');
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
371 line[line.length] = quoted;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
372 pos = nextquote+2;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
373 continue;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
374 } else if ( text.charAt(nextquote+1) == "\n" || // end of line
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
375 len==nextquote+1 ) { // end of file
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
376 var quoted = text.substr( pos+1, nextquote-pos-1 );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
377 quoted = quoted.replace(/""/g,'"');
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
378 line[line.length] = quoted;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
379 pos = nextquote+2;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
380 break;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
381 } else {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
382 // invalid column
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
383 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
384 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
385 var nextcomma = text.indexOf( ",", pos );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
386 var nextnline = text.indexOf( "\n", pos );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
387 if ( nextnline < 0 ) nextnline = len;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
388 if ( nextcomma > -1 && nextcomma < nextnline ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
389 line[line.length] = text.substr( pos, nextcomma-pos );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
390 pos = nextcomma+1;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
391 } else { // end of line
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
392 line[line.length] = text.substr( pos, nextnline-pos );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
393 pos = nextnline+1;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
394 break;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
395 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
396 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
397 if ( line.length >= 0 ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
398 table[table.length] = line; // push line
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
399 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
400 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
401 if ( table.length < 0 ) return; // null data
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
402 return table;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
403 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
404
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
405 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
406 // class: JKL.ParseXML.CSVmap
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
407
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
408 JKL.ParseXML.CSVmap = function ( url, query, method ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
409 // debug.print( "new JKL.ParseXML.CSVmap( '"+url+"', '"+query+"', '"+method+"' );" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
410 this.http = new JKL.ParseXML.HTTP( url, query, method, true );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
411 return this;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
412 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
413
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
414 JKL.ParseXML.CSVmap.prototype.parse = JKL.ParseXML.prototype.parse;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
415 JKL.ParseXML.CSVmap.prototype.async = JKL.ParseXML.prototype.async;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
416 JKL.ParseXML.CSVmap.prototype.onerror = JKL.ParseXML.prototype.onerror;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
417 JKL.ParseXML.CSVmap.prototype.parseCSV = JKL.ParseXML.CSV.prototype.parseCSV;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
418
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
419 JKL.ParseXML.CSVmap.prototype.parseResponse = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
420 var text = this.http.responseText();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
421 var source = this.parseCSV( text );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
422 if ( ! source ) return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
423 if ( source.length < 0 ) return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
424
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
425 var title = source.shift(); // first line as title
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
426 var data = [];
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
427 for( var i=0; i<source.length; i++ ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
428 var hash = {};
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
429 for( var j=0; j<title.length && j<source[i].length; j++ ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
430 hash[title[j]] = source[i][j]; // array to map
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
431 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
432 data[data.length] = hash; // push line
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
433 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
434 return data;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
435 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
436
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
437 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
438 // class: JKL.ParseXML.LoadVars
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
439
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
440 JKL.ParseXML.LoadVars = function ( url, query, method ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
441 // debug.print( "new JKL.ParseXML.LoadVars( '"+url+"', '"+query+"', '"+method+"' );" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
442 this.http = new JKL.ParseXML.HTTP( url, query, method, true );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
443 return this;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
444 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
445
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
446 JKL.ParseXML.LoadVars.prototype.parse = JKL.ParseXML.prototype.parse;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
447 JKL.ParseXML.LoadVars.prototype.async = JKL.ParseXML.prototype.async;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
448 JKL.ParseXML.LoadVars.prototype.onerror = JKL.ParseXML.prototype.onerror;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
449
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
450 JKL.ParseXML.LoadVars.prototype.parseResponse = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
451 var text = this.http.responseText();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
452 text = text.replace( /\r\n?/g, "\n" ); // new line character
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
453 var hash = {};
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
454 var list = text.split( "&" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
455 for( var i=0; i<list.length; i++ ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
456 var eq = list[i].indexOf( "=" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
457 if ( eq > -1 ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
458 var key = decodeURIComponent(list[i].substr(0,eq).replace("+","%20"));
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
459 var val = decodeURIComponent(list[i].substr(eq+1).replace("+","%20"));
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
460 hash[key] = val;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
461 } else {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
462 hash[list[i]] = "";
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
463 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
464 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
465 return hash;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
466 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
467
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
468 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
469 // class: JKL.ParseXML.HTTP
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
470 // constructer: new JKL.ParseXML.HTTP()
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
471
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
472 JKL.ParseXML.HTTP = function( url, query, method, textmode ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
473 // debug.print( "new JKL.ParseXML.HTTP( '"+url+"', '"+query+"', '"+method+"', '"+textmode+"' );" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
474 this.url = url;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
475 if ( typeof(query) == "string" ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
476 this.query = query;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
477 } else {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
478 this.query = "";
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
479 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
480 if ( method ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
481 this.method = method;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
482 } else if ( typeof(query) == "string" ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
483 this.method = "POST";
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
484 } else {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
485 this.method = "GET";
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
486 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
487 this.textmode = textmode ? true : false;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
488 this.req = null;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
489 this.xmldom_flag = false;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
490 this.onerror_func = null;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
491 this.callback_func = null;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
492 this.already_done = null;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
493 return this;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
494 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
495
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
496 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
497 // class variables
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
498
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
499 JKL.ParseXML.HTTP.REQUEST_TYPE = "application/x-www-form-urlencoded";
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
500 JKL.ParseXML.HTTP.ACTIVEX_XMLDOM = "Microsoft.XMLDOM"; // Msxml2.DOMDocument.5.0
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
501 JKL.ParseXML.HTTP.ACTIVEX_XMLHTTP = "Microsoft.XMLHTTP"; // Msxml2.XMLHTTP.3.0
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
502 JKL.ParseXML.HTTP.EPOCH_TIMESTAMP = "Thu, 01 Jun 1970 00:00:00 GMT"
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
503
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
504 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
505
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
506 JKL.ParseXML.HTTP.prototype.onerror = JKL.ParseXML.prototype.onerror;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
507 JKL.ParseXML.HTTP.prototype.async = function( func ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
508 this.async_func = func;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
509 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
510
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
511 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
512 // [IE+IXMLDOMElement]
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
513 // XML text/xml OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
514 // XML application/rdf+xml OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
515 // TEXT text/plain NG
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
516 // TEXT others NG
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
517 // [IE+IXMLHttpRequest]
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
518 // XML text/xml OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
519 // XML application/rdf+xml NG
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
520 // TEXT text/plain OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
521 // TEXT others OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
522 // [Firefox+XMLHttpRequest]
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
523 // XML text/xml OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
524 // XML application/rdf+xml OK (overrideMimeType)
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
525 // TEXT text/plain OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
526 // TEXT others OK (overrideMimeType)
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
527 // [Opera+XMLHttpRequest]
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
528 // XML text/xml OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
529 // XML application/rdf+xml OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
530 // TEXT text/plain OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
531 // TEXT others OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
532 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
533
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
534 JKL.ParseXML.HTTP.prototype.load = function() {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
535 // create XMLHttpRequest object
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
536 if ( window.ActiveXObject ) { // IE5.5,6,7
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
537 var activex = JKL.ParseXML.HTTP.ACTIVEX_XMLHTTP; // IXMLHttpRequest
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
538 if ( this.method == "GET" && ! this.textmode ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
539 // use IXMLDOMElement to accept any mime types
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
540 // because overrideMimeType() is not available on IE6
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
541 activex = JKL.ParseXML.HTTP.ACTIVEX_XMLDOM; // IXMLDOMElement
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
542 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
543 // debug.print( "new ActiveXObject( '"+activex+"' )" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
544 this.req = new ActiveXObject( activex );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
545 } else if ( window.XMLHttpRequest ) { // Firefox, Opera, iCab
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
546 // debug.print( "new XMLHttpRequest()" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
547 this.req = new XMLHttpRequest();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
548 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
549
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
550 // async mode when call back function is specified
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
551 var async_flag = this.async_func ? true : false;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
552 // debug.print( "async: "+ async_flag );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
553
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
554 // open for XMLHTTPRequest (not for IXMLDOMElement)
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
555 if ( typeof(this.req.send) != "undefined" ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
556 // debug.print( "open( '"+this.method+"', '"+this.url+"', "+async_flag+" );" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
557 this.req.open( this.method, this.url, async_flag );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
558 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
559
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
560 // // If-Modified-Since: Thu, 01 Jun 1970 00:00:00 GMT
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
561 // if ( typeof(this.req.setRequestHeader) != "undefined" ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
562 // // debug.print( "If-Modified-Since"+JKL.ParseXML.HTTP.EPOCH_TIMESTAMP );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
563 // this.req.setRequestHeader( "If-Modified-Since", JKL.ParseXML.HTTP.EPOCH_TIMESTAMP );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
564 // }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
565
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
566 // Content-Type: application/x-www-form-urlencoded (request header)
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
567 // Some server does not accept without request content-type.
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
568 if ( typeof(this.req.setRequestHeader) != "undefined" ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
569 // debug.print( "Content-Type: "+JKL.ParseXML.HTTP.REQUEST_TYPE+" (request)" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
570 this.req.setRequestHeader( "Content-Type", JKL.ParseXML.HTTP.REQUEST_TYPE );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
571 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
572
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
573 // Content-Type: text/xml (response header)
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
574 // FireFox does not accept other mime types like application/rdf+xml etc.
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
575 if ( typeof(this.req.overrideMimeType) != "undefined" && ! this.textmode ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
576 // debug.print( "Content-Type: "+JKL.ParseXML.MIME_TYPE_XML+" (response)" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
577 this.req.overrideMimeType( JKL.ParseXML.MIME_TYPE_XML );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
578 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
579
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
580 // set call back handler when async mode
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
581 if ( async_flag ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
582 var copy = this;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
583 copy.already_done = false; // not parsed yet
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
584 var check_func = function () {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
585 if ( copy.req.readyState != 4 ) return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
586 // debug.print( "readyState(async): "+copy.req.readyState );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
587 var succeed = copy.checkResponse();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
588 // debug.print( "checkResponse(async): "+succeed );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
589 if ( ! succeed ) return; // failed
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
590 if ( copy.already_done ) return; // parse only once
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
591 copy.already_done = true; // already parsed
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
592 copy.async_func(); // call back async
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
593 };
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
594 this.req.onreadystatechange = check_func;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
595 // for document.implementation.createDocument
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
596 // this.req.onload = check_func;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
597 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
598
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
599 // send the request and query string
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
600 if ( typeof(this.req.send) != "undefined" ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
601 // debug.print( "XMLHTTPRequest: send( '"+this.query+"' );" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
602 this.req.send( this.query ); // XMLHTTPRequest
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
603 } else if ( typeof(this.req.load) != "undefined" ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
604 // debug.print( "IXMLDOMElement: load( '"+this.url+"' );" );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
605 this.req.async = async_flag;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
606 this.req.load( this.url ); // IXMLDOMElement
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
607 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
608
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
609 // just return when async mode
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
610 if ( async_flag ) return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
611
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
612 var succeed = this.checkResponse();
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
613 // debug.print( "checkResponse(sync): "+succeed );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
614 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
615
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
616 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
617 // method: checkResponse()
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
618
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
619 JKL.ParseXML.HTTP.prototype.checkResponse = function() {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
620 // parseError on IXMLDOMElement
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
621 if ( this.req.parseError && this.req.parseError.errorCode != 0 ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
622 // debug.print( "parseError: "+this.req.parseError.reason );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
623 if ( this.onerror_func ) this.onerror_func( this.req.parseError.reason );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
624 return false; // failed
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
625 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
626
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
627 // HTTP response code
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
628 if ( this.req.status-0 > 0 &&
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
629 this.req.status != 200 && // OK
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
630 this.req.status != 206 && // Partial Content
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
631 this.req.status != 304 ) { // Not Modified
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
632 // debug.print( "status: "+this.req.status );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
633 if ( this.onerror_func ) this.onerror_func( this.req.status );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
634 return false; // failed
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
635 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
636
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
637 return true; // succeed
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
638 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
639
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
640 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
641 // method: documentElement()
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
642 // return: XML DOM in response body
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
643
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
644 JKL.ParseXML.HTTP.prototype.documentElement = function() {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
645 // debug.print( "documentElement: "+this.req );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
646 if ( ! this.req ) return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
647 if ( this.req.responseXML ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
648 return this.req.responseXML.documentElement; // XMLHTTPRequest
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
649 } else {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
650 return this.req.documentElement; // IXMLDOMDocument
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
651 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
652 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
653
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
654 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
655 // method: responseText()
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
656 // return: text string in response body
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
657
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
658 JKL.ParseXML.HTTP.prototype.responseText = function() {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
659 // debug.print( "responseText: "+this.req );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
660 if ( ! this.req ) return;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
661
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
662 // Safari and Konqueror cannot understand the encoding of text files.
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
663 if ( navigator.appVersion.match( "KHTML" ) ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
664 var esc = escape( this.req.responseText );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
665 // debug.print( "escape: "+esc );
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
666 if ( ! esc.match("%u") && esc.match("%") ) {
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
667 return decodeURIComponent(esc);
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
668 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
669 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
670
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
671 return this.req.responseText;
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
672 }
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
673
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
674 // ================================================================
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
675 // http://msdn.microsoft.com/library/en-us/xmlsdk/html/d051f7c5-e882-42e8-a5b6-d1ce67af275c.asp
fccccbcc94be xml_file_read
e085737@tamayose-syuuichi-no-macbook.local
parents:
diff changeset
676 // ================================================================