2

私の問題は、htmlドキュメントからすべてのテーブルを抽出し、それらをテーブルのリストに配置する必要があることです。

したがって、終了関数の型は次のようになります。

getTable :: a [XmlTree] [[String]]

たとえば、次のxmlを使用します。

<table class="t1">
<tr>
    <td>x</td>
    <td>y</td>
</tr>
<tr>
    <td>a</td>
    <td>b</td>
</tr>
</table>
<table class="t2">
<tr>
    <td>3</td>
    <td>5</td>
</tr>
<tr>
    <td>toto</td>
    <td>titi</td>
</tr>
</table>

1つのxmlTree(example1)またはタイプ[XmlTree]を提供するすべてのタグ "tables"からすべての行を取得する方法は知っていますが、test2の結果内に矢印example1をマップする方法がわかりません。

当たり前のことだと思いますが、見つかりません。

test2 ::  IO [[XmlTree]]
test2 = runX $ parseXML "table.xml" >>> is "table">>> listA getChildren

example1 ::  ArrowXml a => a XmlTree [String]
example1  = is "table" /> listA (getChildren >>> is "td"  /> getText)
4

1 に答える 1

3

あなたが持っているのと同じ一般的な考えを使用して、私たちはこのようexample1に書くことができますgetTable

getTable :: ArrowXml a => a XmlTree [[String]]
getTable =  hasName "table" >>> listA (rows >>> listA cols) where
    rows = getChildren >>> hasName "tr"
    cols = getChildren >>> hasName "td" /> getText

サンプルドキュメントで矢印を実行すると、

[[["x","y"],["a","b"]],[["3","5"],["toto","titi"]]]
于 2012-06-06T11:19:56.423 に答える