Skip to content

Experimental: add dom wrapper #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quick-xml"
version = "0.6.2"
version = "0.7.0"
authors = ["Johann Tuffe <tafia973@gmail.com>"]
description = "High performance xml reader and writer"

Expand Down
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
- test: Adding missing tests
- chore: Changes to the build process or auxiliary tools/libraries/documentation

## 0.7.0
- feat: add dom module to have a DOM like interface wrapper

## 0.6.2
- fix: another overflow bug found with cargo-fuzz
- refactor: update dependencies
Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,38 @@ let expected = r#"<my_elem k1="v1" k2="v2" my-key="some value"><child>text</chil
assert_eq!(result, expected.as_bytes());
```

### Experimental DOM like interface

```rust
use quick_xml::dom::Node;

// loads the entire file in memory and converts it into a `Node`
let path = "/path/to/my/file.xml";
let mut root = Node::open(path).expect("cannot read file");

// gets specific nodes following a particular path
{
let nodes = root.select("a/b/c");
for n in nodes {
println!("node: name: {}, attributes count: {}, children count: {}",
n.name(), n.attributes().len(), n.children().len());
}

// alternatively, in we only need these nodes, there is a faster version
// which performs less allocation:
//
// let nodes = Node::open_xpath(path, "a/b/c").unwrap();
}

// Now let's say we want to modify the document
if let Some(child) = root.children_mut().get_mut(0) {
child.attributes_mut().push(("My new key".to_string(), "My new value".to_string()));
}

// we're done, we can save it back to a new file
root.save("/dev/null").expect("cannot save file");
```

## Performance

quick-xml is 40+ times faster than the widely used [xml-rs](https://crates.io/crates/xml-rs) crate.
Expand Down
Loading