I.åé¡ã®æ¬è³ªã
ãã¡ãããXMLHttpRequestã¯äž»ãªç®çã®ãªã¹ãã«HTMLãªã¯ãšã¹ããå«ãã§ããŸããããã®ããŒã«ã¯ããé »ç¹ã«XMLãJSONããŸãã¯ãã¬ãŒã³ããã¹ããšããåãããŸãã
ãã ããXMLHttpRequest + HTMLãã³ãã«ã¯ãé»åã¡ãŒã«ã®ãµãã¹ã¯ãªãã·ã§ã³ãRSSããŸãã¯ãã®ä»ã®äœã³ã¹ãAPIãæäŸããªãããŸãã¯ãããã®ãµãŒãã¹ã«ããã€ãã®å¶éãæäŸããªããã¥ãŒã¹ãµã€ããããã¯ã°ã©ãŠã³ãã§ããŒãªã³ã°ãããã©ãŠã¶ãŒæ¡åŒµæ©èœãäœæããå Žåã«é©åã«æ©èœããŸãã
Firefoxã®ããã€ãã®æ¡åŒµæ©èœãäœæãããšããç§ã¯ãã®ãããªããŒãºã«åºäŒããŸããã æ£èŠè¡šçŸã䜿çšããŠXMLHttpRequestããåä¿¡ããHTMLã³ãŒããæäœããããšã¯ãéåžžã«ä¿¡é Œæ§ãäœããé¢åãªæ¹æ³ã§ãã é©åãªXMLã®XMLHttpRequestããDOMãååŸã§ããŸãã ãã®ããã éçºè ã®ãµã€ãã§æ³šæãå¿ èŠãªãã³ãã«åŸãå¿ èŠããããŸãã ã ãã ããFirefox 11以éã XMLHttpRequestããDOMãçŽæ¥ååŸããããšãå¯èœã«ãªããFirefox 12ã§ã¿ã€ã ã¢ãŠãåŠçãè¿œå ãããŸããã
2ã€ã®å°ããªãã©ãŒã©ã ã®æ°ãããããã¯ã®ããã€ã³ãžã±ãŒã¿ãŒãäœæããæ°ããæ©äŒãçµéšããéåžžã«äŸ¿å©ã§ããããšãããããŸãã ïŒ50è¡ã®ã³ãŒããšCustomButtonsæ¡åŒµ-ããã¯ãã¿ã€ããŒããŒãªã³ã°ãš4ã€ã®ç¶æ ãåããæ¢è£œã®ã€ã³ãžã±ãŒã¿ãŒã§ãããã¥ãŒã¹ãªãããã¥ãŒã¹ããããšã©ãŒãã¿ã€ã ã¢ãŠãã詳现ã«ã€ããŠã¯ãã¡ããã芧ãã ãã ïŒã ãã¹ãŠãæèšã®ããã«æ©èœããŸããã
ãããã£ãŠãæ¡åŒµæ©èœã®ã³ãŒãããå€ãæŸèæããã¹ãŠåé€ããããã«æ°ãã䟿å©ãªè§£æãå°å ¥ããããšããŸããã ãã ãã rutracker.org Webãµã€ãã§äœæ¥ããŠãããšãã«ãå¥åŠãªåé¡ãçºçããŸããïŒWindows XPã§ã®æåŸã®å€éãã«ãã§ãã¹ããè¡ââãããŸããã³ãŒããšèšèªã®ãã¹ãŠã®ééãããa ã³ããŸããæ®å¿µãªããããã®åéã§ã®çµéšã¯éåžžã«å°ãªãã§ãïŒ ãïŒã
次ã®ç°¡åãªã³ãŒãäŸã¯ãã»ãšãã©åžžã«ã¿ã€ã ã¢ãŠãã«ãªããŸãïŒæ€èšŒã®ããã«ããµã€ãã«ãã°ã€ã³ããå¿ èŠããããŸã-ãããéèŠã§ããçç±ãæããã«ãªããŸãïŒ
var xhr = new XMLHttpRequest(); xhr.mozBackgroundRequest = true; xhr.open("GET", "http://rutracker.org/forum/index.php", true); xhr.timeout = 10000; xhr.channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE; xhr.responseType = "document"; xhr.onload = function() { alert(this.responseXML.title); } xhr.onerror = function() { alert("Error!"); } xhr.ontimeout = function() { alert("Timeout!"); } xhr.send(null);
ãŸããDOMã§ã®HTML解æã«ã¯åé¡ããããŸããããã¯ããµã€ããé æ»ãªãããŒãžãæäŸããããã§ããããšãã°ã解æãªãã®æ¬¡ã®ã³ãŒãã¯ããããããšãªãæ©èœããŸãã
var xhr = new XMLHttpRequest(); xhr.mozBackgroundRequest = true; xhr.open("GET", "http://rutracker.org/forum/index.php", true); xhr.timeout = 10000; xhr.channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE; xhr.onload = function() { alert(this.responseText.match(/<title>.+?<\/title>/i)[0]); } xhr.onerror = function() { alert("Error!"); } xhr.ontimeout = function() { alert("Timeout!"); } xhr.send(null);
XMLHttpRequest ä»æ§ã§ã¯ãDOMã§HTML / XMLã解æããå Žåãçµæã®ããã¥ã¡ã³ãããªãŒã®ã¹ã¯ãªããã¯å®è¡ããããåç §ããããªãœãŒã¹ã¯ããŒããããã é¢é£ããXSLTã¯é©çšãããŸãããã€ãŸããã¹ã¯ãªããã¯åŠçãããããªãœãŒã¹ã¯ããŒããããŸããïŒç¢ºèªãããŸãïŒèšè¿°ããããªã¯ãšã¹ãã®HTTPã¢ã¯ãã£ããã£ãç£èŠããïŒããããã®åŽã§é 延ãçºçããããšã¯ãããŸããã å¯äžã®åé¡ã¯ãDOMèªäœã®æ§é ã«ã®ã¿ååšããŸããäœããã®çç±ã§ã解æãããªãŒãºããç䌌ã¿ã€ã ã¢ãŠããäœæãããŸãã
IIã è¿œå ã®èŠ³å¯ã
次ã«ãDOMçµ±èšçšã®å°ããªã¹ã¯ãªãããäœæãããã®å©ããåããŠåé¡ããŒãžã®åæãéå§ããŸããã
var doc = content.document; var root = doc.documentElement; var text_char = root.textContent.length; var elm_nodes = doc.evaluate(".//*", root, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength; var txt_nodes = doc.evaluate(".//text()", root, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength; var com_nodes = doc.evaluate(".//comment()", root, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength; var all_nodes = doc.evaluate(".//node()", root, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength; var max_nst_lv = 0; var max_nst_lv_nodes = 0; for (var level = 1, pattern = "./node()"; level <= 50; level++, pattern += "/node()") { var elm_num = doc.evaluate(pattern,root,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength; if (elm_num) { max_nst_lv = level; max_nst_lv_nodes = elm_num; } } alert( text_char + "\ttext characters\n\n" + elm_nodes + "\telement nodes\n" + txt_nodes + "\ttext nodes\n" + com_nodes + "\tcomment nodes\n" + all_nodes + "\tall nodes\n\n" + max_nst_lv_nodes + " nodes in the " + max_nst_lv + " maximum nesting level\n" );
以äžã«ãããã«è€éãªããŒã¿ã瀺ããŸãã
1. JavaScriptããªãã«ãããã©ãŒã©ã ã®ã¡ã€ã³ããŒãžã«ã¯ãããã¹ãããŒãã®49677æåã4192ã®HTMLèŠçŽ ã4285ã®ããã¹ãããŒãã77ã®ã³ã¡ã³ããåèš8554ã®ããŒãããããŸãã ããŒãã®æ倧25çªç®ã®ãã¹ãã¬ãã«ã«ãã577ããŒãã
2.ãã©ãŒã©ã ãçµäºããŠæš©éã®ãªããŠãŒã¶ãŒã®ããŒãžãããŠã³ããŒããããšã次ã®çµ±èšãåŸãããŸããããã¹ãããŒãã®47831æåã3336 HTMLèŠçŽ ã4094ããã¹ãããŒãã73ã³ã¡ã³ããåèš7503ããŒãã ããŒãã®æ倧24çªç®ã®ãã¹ãã¬ãã«ã«ãã1136ããŒãã æ§é ã¯æããã«åçŽã§ããããã©ãŒã©ã ãé¢ããããšã§åé¡ã®ããã³ãŒããè©ŠããŠãïŒã€ãŸãããã®ããŒãžã§èš±å¯ãããŠããªããŠãŒã¶ãŒã®ããã«ïŒãã¿ã€ã ã¢ãŠãã¯çºçããŸããã
3.åé¡ããŒãžããã¹ããµã€ãã«ã¢ããããŒãããŠããã®æ§é ãåŸã ã«ç°¡çŽ åããããšããŸããã ããšãã°ãã¯ã©ã¹row1 ïŒããããŒããŒãžã®ããŒãã«ã®ãã©ãŒã©ã ãšãµããã©ãŒã©ã ã®èŠåºãïŒãæã€ãã¹ãŠã®
td
èŠçŽ ãåé€ããä»ã«äœãå€æŽããªãå Žåã次ã®çµ±èšãåŸãããŸãïŒããã¹ãããŒãã®20,450æåã1355 HTMLèŠçŽ ã1726ããã¹ãããŒãã77ã³ã¡ã³ããåèš3158ããŒã; ããŒãã®æ倧25çªç®ã®ãã¹ãã¬ãã«ã«ãã8ã€ã®ããŒãã ç¹°ãè¿ããŸãããäŸå€ãã»ãšãã©ãªããã®ããŒãžã§ã¯ã¿ã€ã ã¢ãŠãã¯çºçããŸããã
4.
script
èŠçŽ ã«ã¯éåžžã«å¥åŠãªæå³ããããŸãã ã¿ã€ãã«ããŒãžã«ã¯19åãããŸãïŒé ãšäœã®çµã¿åãããããŒããåã蟌ã¿ïŒã ãããã®èŠçŽ ã®ã¿ãåé€ãããšãããŒãžã®ã¿ã€ã ã¢ãŠããåæ¢ããŸãã ããã«ãæåŸããæåãŸã§åé€ããå Žåã¯ããã¹ãŠãåé€ããå¿ èŠããããŸãïŒæåã«ããŒããããã¹ã¯ãªãããå é ã«çœ®ããŠããã¿ã€ã ã¢ãŠãã¯ç¶ããŸãïŒã ãŸããæåããæåŸãŸã§åé€ãããšããã«ãŒã«ãåºæ¬çãªæé ãFAQãã»ã¯ã·ã§ã³ã®forum_descé ãã¯ã©ã¹ã®
p
èŠçŽ ã«çµã¿èŸŒãŸããã¹ã¯ãªãããåé€ããåŸã«ã¿ã€ã ã¢ãŠããåæ¢ããŸãããã®åŸãããã«6ã€ã®ã¹ã¯ãªãããæ®ãããšãã§ããã¿ã€ã ã¢ãŠãã¯åæ¢ããŸãïŒããã«ãåé€ãã®ã¹ã¯ãªããã®ã¿ãåé¡ã解決ããŸããïŒã ããã«ã19åã®ã¹ã¯ãªãããã¹ãŠããã³ãŒããsrcå±æ§ããªã空ã®
script
èŠçŽ ã«çœ®ãæããããå Žåãã¿ã€ã ã¢ãŠããæ®ããŸãã ãã ãããããã®ç©ºã®èŠçŽ ãåãéã®åã空ã®
style
èŠçŽ ã«çœ®ãæãããšãã¿ã€ã ã¢ãŠãã¯ããã«æ¶ããŸãã
5. PERLã§ã¹ã¯ãªããã䜿çšããŠãå€å°è€éãªæ§é ïŒãã ãã
script
èŠçŽ ãªãïŒã§ãã¹ãHTMLãäœæããããšããŸããã çµæã¯ã次ã®çµ±èšãåãããµã€ãºãã»ãŒ10ã¡ã¬ãã€ãã®ãã¡ã€ã«ã§ãããããã¹ãããŒãã®9732505æåã25004 HTMLèŠçŽ ã2500 2ããã¹ãããŒãã1000ã³ã¡ã³ããåèš51006ããŒãã æ倧27ã¬ãã«ã®ãã¹ãã§1000ãããã æ§é ã¯åé¡ããŒãžããã倧ããè€éã§ããããã«èŠããŸãããã¿ã€ã ã¢ãŠãã¯çºçããŸããã åé¡ã¯ãèŠçŽ ã®é/è€éã/ç¹ç°æ§ã®ãããŸããªçµã¿åããã«ããããšãæããã«ãªããŸããã
6.ãã®ã·ãã¥ã¬ãŒããããããŒãžã«
script
èŠçŽ ãè¿œå ããã ãã§ãã¿ã€ã ã¢ãŠããè¿ãããŸããïŒãã®é£ããã±ãŒã¹ã§ã¯ã¿ã€ã ã¢ãŠããããå€ã1åã«å¢ãããŸãããïŒã
IIIã ç°¡åã«åçŸå¯èœãªãŠãŒã¹ã±ãŒã¹ãäœæããŸãã
PERLã®ãã®ãããªã¹ã¯ãªããã®å©ããåããŠããã©ãã«ãŒããŒã ããŒãžã®æ§é ã«å¹æµããæ§é äžã®åé¡ã®ç¹å®ã®éèŠãªæå°å€ãéæããããšãã§ããŸããã
use strict; use warnings; open(OUTPUT, '>:raw:encoding(UTF-8)', "test.html") or die "Cannot write to test.html: $!\n"; print OUTPUT "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\n" . "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><title>Test</title></head><body>" . (("<div class='abcd'>abcd" x 25 . "</div>" x 25 ) x 10 . "<script type='text/javascript'>var a = 1234;</script>") x 20 . "</body></html>\n"; close(OUTPUT);
ããŒãžçµ±èšïŒããã¹ãããŒãã«20,265æåã5024 HTMLèŠçŽ ã5022ããã¹ãããŒãã0ã³ã¡ã³ããåèš10046ããŒãã ãã¹ãããŒãã®æ倧27ã¬ãã«ã§200ããŒãã 20åã®åºæ¬
script
èŠçŽ ãå«ãã 10åã®è©Šè¡ã§10åã®ã¿ã€ã ã¢ãŠããçºçããŸãã
æ§é ãåçŽåããããããªã¥ãŒã ãæžããããŸããŸãªè©Šã¿ã«ãããã¿ã€ã ã¢ãŠãã®ç¢ºçã¯äœäžããŸãããäºæž¬äžå¯èœãªæ¹æ³ã§ïŒãããã®åçŽåã®ãããããåã¹ã¯ãªãããå ã®ã³ãŒãã«æ»ãåã«éè€ããŸããã§ããïŒïŒ
-ãã¹ãŠã®
script
èŠçŽ ãã³ãŒãã®æåŸã«ç§»åããŸãïŒä»ã«äœãå€åãããçµ±èšãåããŸãŸã§ããã«ããããããïŒïŒ10åã®è©Šè¡ã§0åã®ã¿ã€ã ã¢ãŠãã
-
script
èŠçŽ ãã1ã€ã®å±æ§ãšåãããã¹ãã³ã³ãã³ããæã€
span
èŠçŽ ã§çœ®ãæã
script
ïŒæåŸã«ç§»åããã«ïŒïŒ10åã®è©Šè¡ã§0åã®ã¿ã€ã ã¢ãŠãã
-3æåã®ã¹ã¯ãªããããã¹ãã®ç¥èªïŒ10ã®ãã¡7ã€ã®ã¿ã€ã ã¢ãŠãã
-ã¹ã¯ãªããã®å å®¹å šäœãåé€ããïŒç©ºã®ã¿ã°ã®ã¿ãæ®ãïŒïŒ10åã®è©Šè¡ã®ãã¡6åã®ã¿ã€ã ã¢ãŠãã
div
èŠçŽ ã®ããã¹ãã1æåã«åæžïŒ10åã®è©Šè¡ãã5åã®ã¿ã€ã ã¢ãŠãã
div
èŠçŽ ã®ããã¹ãã®å®å šãªåé€ïŒç©ºçœããŒãžã衚瀺ãããŸãïŒïŒ10åã®è©Šè¡ã®ãã¡7åã®ã¿ã€ã ã¢ãŠãã
div
èŠçŽ ã®classå±æ§ã1æåã«åæžïŒ10åã®è©Šè¡ãã8åã®ã¿ã€ã ã¢ãŠãã
div
èŠçŽ ã®classå±æ§ã®åé€ïŒ10åã®è©Šè¡ãã1åã®ã¿ã€ã ã¢ãŠãã
-
script
èŠçŽ ã®æ°ã2ã«æžãã
script
ïŒã³ãŒãã®éäžãšæåŸïŒïŒããäžåºŠ10åã®è©Šè¡ãã10åã®ã¿ã€ã ã¢ãŠãã
-
script
èŠçŽ ã®æ°ã1ã«æžãã
script
ïŒã³ãŒãã®å é ïŒïŒ10åã®è©Šè¡ã§åã10åã®ã¿ã€ã ã¢ãŠãããããŸãïŒãã ãããã®èŠçŽ ãã³ãŒãã®æåŸã«ç§»åãããšãã¿ã€ã ã¢ãŠãã¯å®å šã«æ¶ããŸãïŒã
-ãã¹ãã®æ倧ã¬ãã«ãç¶æããªããã
div
èŠçŽ ïŒããã³ããã¹ãããŒãïŒã®æ°ãååã«ããŸãïŒ10åã®è©Šè¡ã®ãã¡3åã®ã¿ã€ã ã¢ãŠãã
-ãã¹ãã®æ倧ã¬ãã«ãååã«æžãããŸãïŒèŠçŽ ãšããã¹ãããŒãã®åèšæ°ã¯ã»ãŒåããŸãŸã§ããããã¹ãã®æ倧ã¬ãã«ã®èŠçŽ æ°ã¯2åã«ãªããŸãïŒïŒ10åã®è©Šè¡ã®ãã¡7åã®ã¿ã€ã ã¢ãŠãã
-ãšã¬ã¡ã³ãã®åèšæ°ãç¶æããªããããã¹ãã®æ倧ã¬ãã«ã3ïŒ
body/div/
ããã¹ããŸãã¯
body/script/
ããã¹ãïŒã«åæžïŒ10åã®è©Šè¡ã§8åã®ã¿ã€ã ã¢ãŠãã
IVã äºå調æ»çµæã
èšèŒãããŠãããã¹ãŠã®ã±ãŒã¹ã§ãããã»ããµã®éè² è·ã¯èŠ³å¯ãããªãã£ããããããŒããŠã§ã¢ããã³ã°ã®ããã«ããçç±ã¯ãããŸããïŒãããã¯ãŒã¯é 延ãšåæ§ã«ãã³ãŒãã¯äžç¬ã§ååŸãããããŒãžã¯ã¯ããã«çãã¿ã€ã ã¢ãŠãã§ãã©ãŠã¶ã«ã¬ã³ããªã³ã°ãããŸãïŒã æããã«ãXMLHttpRequestã§ã¯ãããã€ãã®éããããªãœãŒã¹ãDOMã®HTML解æã«å²ãåœãŠãããŸãããããã¯ç°ãªããã©ã¡ãŒã¿ãŒã®çµã¿åããã«ãã£ãŠäœ¿ãæããããŸãã ããã«ã
script
èŠçŽ ïŒå®è¡ãããããšãããããŸããïŒãšãç¹ã«ã³ãŒãå ã§ã®é åºã¯ãäžå¯è§£ãªåœ¹å²ãæãããŸãã ãããåœãŠã¯ãŸãå ŽåããªãœãŒã¹ãå¢ãããèŠçŽ ã®ã¿ã€ããšé åºãžã®å¥åŠãªäŸåãæžãã䟡å€ããããŸããåé¡ã¯æ±ºããŠé ããã®ã§ã¯ãªããæ¡åŒµæ©èœã®éåžžã®éçºã®éçšã§çããããã§ãã
V.次ã¯äœã§ããã
åé¡ã®åæãå§ããã°ããã§ãããã€ãã®ãµã€ãã§ã¢ããã€ã¹ãæ±ãããšããforums.mozilla.orgã®ç®¡çè ã¯ããã©ãŒãã³ã¹ãã°ãææ¡ããCoreïŒDOMã»ã¯ã·ã§ã³ã§ãåçŸãããç¶æ³ã説æããã¡ãã»ãŒãžãbugzilla.mozilla.orgã«éä¿¡ããããå§ããŸããã ããããç§ã¯éåžžã«å°ãªãããŒã¿ãæã£ãŠããŸããããããŠä»ããããã¯éåžžã«äžæçã§ãã ãããã£ãŠãåé¡ãç¹å®ããŠæ確ã«èª¬æã§ããããã«ããèæ ®äºé ã«æè¬ããŸãã ãã以å€ã®å Žåã¯ããã®ã·ãŒãããã¹ãŠè±èªã«ç¿»èš³ããå¿ èŠãããïŒèšèªãšè³æã«é¢ããç§ã®ç¥èã¬ãã«ã§ã¯ç§ã«ãšã£ãŠã¯éåžžã«å°é£ã§ãïŒããã®ãŸãŸbugzilla.mozilla.orgã«æçš¿ããå¿ èŠããããŸãããã¡ãããããã¯ä»ã®äººã®æéã«å¯Ÿãã軜reã®è¡šãã§ãã