Doing this splits the `append` method in `ElementBuilder` into two methods. `append` now appends exactly one node, while `append_all` appends an iterator of nodes.
Add `remove_child`, which removes the first child that has a specific name and namespace, then returns it if it exists.
Add a lot of convenience methods on `Node`: `as_text_mut`, `as_element_mut`, `into_text`, `into_element`.
quick-xml's Events seem to always return prefixed names, and the
from_reader function, when comparing name of the pop-ed element, and
received event element, was using the unprefixed name to compare.
quick_xml is way faster than xml-rs
Here is an example with a quick atom parser:
With xml-rs:
test parse_factorio_atom ... bench: 3,295,678 ns/iter (+/- 165,851)
With quick_xml:
test parse_factorio_atom ... bench: 203,215 ns/iter (+/- 13,485)
Unfortunately I had to break the API for this change to happen.
* Element::from_reader now takes `R: BufRead` instead of `R: Read`
* Element::write_to now takes `W: io::Write` instead of `EventWriter<W: Write>`
This migration also allow us to have a write_to function which assumes
we're already in a given namespace (see `write_to_in_namespace`).
This way we don't need to reimplement PartialEq for Element. It's also
way easier to get an attribute by name as we don't need to iterate over
every attribute to see if it exists.
The only side effect is that now, in the Debug output, attributes are
automatically sorted by names instead of being sorted by insertion
order.
Fixes#4
The order of attributes in an `Element` doesn't matter anymore.
`<elem a="b" c="d" />` and `<elem c="d" a="b" />` are now correctly
considered equal.
For that I had to derive `PartialOrd` and `Ord` for `Attribute`.
This allows us to sort cloned vectors of `Attribute` in the `PartialEq`
implementation and compare them instead of the struct `attributes`.
Fixes#3
Instead of adding the local_name of an attribute, if a prefix exists,
add prefix:local_name to allow users to retrieve it via the namespaced
key name.
For example, with this XML:
```
<?xml version="1.0" encoding="utf-8"?>
<root xml:lang="en" >
</root>
```
`root.attr("xml:lang").unwrap()` will now correctly return "en".
`root.attr("lang")` will not retrieve "xml:lang" value anymore.
This is a breaking change.
Fixes#2