在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):ocramz/xeno开源软件地址(OpenSource Url):https://github.com/ocramz/xeno开源编程语言(OpenSource Language):Haskell 98.1%开源软件介绍(OpenSource Introduction):xenoA fast event-based XML parser. Features
Please see the bottom of this file for guidelines on contributing to this library. Performance goalsThe hexml Haskell library uses an XML parser written in C, so that is the baseline we're trying to beat or match roughly. The Memory benchmarks for Xeno:
I memory benchmarked Hexml, but most of its allocation happens in C, which GHC doesn't track. So the data wasn't useful to compare. Speed benchmarks:
DOM ExampleEasy as running the parse function: > parse "<p key='val' x=\"foo\" k=\"\"><a><hr/>hi</a><b>sup</b>hi</p>"
Right
(Node
"p"
[("key", "val"), ("x", "foo"), ("k", "")]
[ Element (Node "a" [] [Element (Node "hr" [] []), Text "hi"])
, Element (Node "b" [] [Text "sup"])
, Text "hi"
]) SAX ExampleQuickly dumping XML: > let input = "Text<tag prop='value'>Hello, World!</tag><x><y prop=\"x\">Content!</y></x>Trailing."
> dump input
"Text"
<tag prop="value">
"Hello, World!"
</tag>
<x>
<y prop="x">
"Content!"
</y>
</x>
"Trailing." Folding over XML: > fold const (\m _ _ -> m + 1) const const const const 0 input -- Count attributes.
Right 2 > fold (\m _ -> m + 1) (\m _ _ -> m) const const const const 0 input -- Count elements.
Right 3 Most general XML processor: process
:: Monad m
=> (ByteString -> m ()) -- ^ Open tag.
-> (ByteString -> ByteString -> m ()) -- ^ Tag attribute.
-> (ByteString -> m ()) -- ^ End open tag.
-> (ByteString -> m ()) -- ^ Text.
-> (ByteString -> m ()) -- ^ Close tag.
-> ByteString -- ^ Input string.
-> m () You can use any monad you want. IO, State, etc. For example, fold openF attrF endOpenF textF closeF s str =
execState
(process
(\name -> modify (\s' -> openF s' name))
(\key value -> modify (\s' -> attrF s' key value))
(\name -> modify (\s' -> endOpenF s' name))
(\text -> modify (\s' -> textF s' text))
(\name -> modify (\s' -> closeF s' name))
str)
s The ContributorsSee CONTRIBUTORS.md Contribution guidelinesAll contributions and bug fixes are welcome and will be credited appropriately, as long as they are aligned with the goals of this library: speed and memory efficiency. In practical terms, patches and additional features should not introduce significant performance regressions. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论