#xml-parser #xml #parse #parser

elementtree

将 XML 文件解析为类似 Python elementtree 的结构

13 个版本 (5 个稳定)

1.2.3 2023 年 1 月 4 日
1.2.2 2022 年 9 月 2 日
1.2.1 2022 年 8 月 22 日
0.7.0 2022 年 1 月 15 日
0.2.0 2017 年 3 月 30 日

#620解析器实现

Download history 5557/week @ 2024-03-14 5358/week @ 2024-03-21 6216/week @ 2024-03-28 7654/week @ 2024-04-04 7715/week @ 2024-04-11 6287/week @ 2024-04-18 6128/week @ 2024-04-25 6537/week @ 2024-05-02 5307/week @ 2024-05-09 6399/week @ 2024-05-16 6393/week @ 2024-05-23 8159/week @ 2024-05-30 7077/week @ 2024-06-06 6308/week @ 2024-06-13 5032/week @ 2024-06-20 4429/week @ 2024-06-27

24,616 每月下载量
用于 26 包 (8 个直接使用)

MIT 许可证

235KB
5.5K SLoC

Rust 的 ElementTree

Build Status Crates.io License rustc 1.56.0 Documentation

该库将 XML 解析为类似 Python ElementTree 的结构。它目前支持基本的读取和写入,具有相当好的命名空间支持,并能够检查文件。

不建议用于大型文档,因为整个文档将加载到内存中。然而,它非常适合处理配置文件等类似事物。

示例

let root = Element::from_reader(r#"<?xml version="1.0"?>
<root xmlns="tag:myns" xmlns:foo="tag:otherns">
    <list a="1" b="2" c="3">
        <item foo:attr="foo1"/>
        <item foo:attr="foo2"/>
        <item foo:attr="foo3"/>
    </list>
</root>
"#.as_bytes()).unwrap();
let list = root.find("{tag:myns}list").unwrap();
for child in list.find_all("{tag:myns}item") {
    println!("attribute: {}", child.get_attr("{tag:otherns}attr").unwrap());
}

依赖项

~0.5–6MB
~14K SLoC