Forums: Open Discussion (Thread #6811)

WWW をデータベースとするとう考え方 (2005-01-22 12:10 by (del#11458) #12584)

 わかりやすい例として、tableタグを使ってあるhtmlを一つのテーブルと見てSQL文を発行するというものがあります。

select Field2
from 'table1.html'
where Field1 = 'Data2.1';
=> Field2 = 'Data2.2'

table1.html
-----------
<html>
<head>
<title>Table1</table>
</head>
<body>
<table border="1">
<tr>
<th>No</th><th>Field1</th><th>Field2</th>
</tr>
<tr>
<td>1</td><td>Data1.1</td><td>Data1.2</td>
</tr>
<tr>
<td>2</td><td>Data2.1</td><td>Data2.2</td>
</tr>
</table>
</body>
</html>

それをlisp的に書くと (2005-01-22 13:13 by (del#11458) #12588)

まず table1.html は次のようになる。

("html" ("head" ("title" "Table1"))
("body"
("table"
((("No" "1") ("Field1" "Data1.1") ("Field2" "Data1.2"))
(("No" "2") ("Field1" "Data2.1") ("Field2" "Data2.2")))
("border" "1"))))

そして検索を lisp的に書くと次のようになる。
(assoc "Field"
(extract (sx (wget "table1.html"))
'(?? ("Field1" "Data2.1") ??)))

?? は任意のリストを表すパタン
wget は wgetのようにデータをとってくる
sx は S式への変換
extract はパタンにあったリストの抽出
Reply to #12584