Bumps the cargo-dependencies group with 30 updates in the / directory: | Package | From | To | | --- | --- | --- | | [acadrust](https://github.com/hakanaktt/acadrust) | `0.6.6` | `0.6.8` | | [log](https://github.com/rust-lang/log) | `0.4.34` | `0.4.35` | | [miniz_oxide](https://github.com/Frommi/miniz_oxide) | `0.8.9` | `0.9.1` | | [weezl](https://github.com/image-rs/weezl) | `0.1.12` | `0.2.1` | | [skrifa](https://github.com/googlefonts/fontations) | `0.44.0` | `0.48.0` | | [jixel](https://github.com/awxkee/jixel) | `0.3.4` | `0.5.7` | | [encoding_rs](https://github.com/hsivonen/encoding_rs) | `0.8.42` | `0.8.44` | | [crc32fast](https://github.com/srijs/rust-crc32fast) | `1.5.2` | `1.5.5` | | [flate2](https://github.com/rust-lang/flate2-rs) | `1.1.10` | `1.1.11` | | [rustix](https://github.com/bytecodealliance/rustix) | `1.1.5` | `1.1.6` | | [moxcms](https://github.com/awxkee/moxcms) | `0.8.1` | `0.9.2` | | [zip](https://github.com/zip-rs/zip2) | `9.1.3` | `9.5.1` | | [rfd](https://github.com/PolyMeilex/rfd) | `0.17.2` | `0.18.0` | | [sha1](https://github.com/RustCrypto/hashes) | `0.10.7` | `0.11.0` | | [cfb](https://github.com/mdsteele/rust-cfb) | `0.15.0` | `0.16.0` | | [quick-xml](https://github.com/tafia/quick-xml) | `0.41.0` | `0.42.0` | | [harfrust](https://github.com/harfbuzz/harfrust) | `0.13.3` | `0.16.0` | | [fontique](https://github.com/linebender/parley) | `0.11.1` | `0.13.0` | | [windows-registry](https://github.com/microsoft/windows-rs) | `0.6.1` | `0.100.0` | | [write-fonts](https://github.com/googlefonts/fontations) | `0.54.1` | `0.56.0` | | [ureq](https://github.com/algesten/ureq) | `3.5.0` | `3.5.2` | | [skera](https://github.com/googlefonts/fontations) | `0.8.0` | `0.10.0` | | [icu_locale_core](https://github.com/unicode-org/icu4x) | `2.3.0` | `2.4.0` | | [icu_provider](https://github.com/unicode-org/icu4x) | `2.3.1` | `2.4.0` | | [icu_provider_blob](https://github.com/unicode-org/icu4x) | `2.3.0` | `2.4.0` | | [jpeg-encoder](https://github.com/vstroebel/jpeg-encoder) | `0.6.1` | `0.7.1` | | [hayro-jpeg2000](https://github.com/LaurenzV/hayro) | `0.3.5` | `0.5.0` | | [tokio](https://github.com/tokio-rs/tokio) | `1.53.2` | `1.54.1` | | [getrandom](https://github.com/rust-random/getrandom) | `0.3.4` | `0.4.3` | | [pgp](https://github.com/rpgp/rpgp) | `0.21.0` | `0.21.1` | Updates `acadrust` from 0.6.6 to 0.6.8 - [Release notes](https://github.com/hakanaktt/acadrust/releases) - [Changelog](https://github.com/hakanaktt/acadrust/blob/main/CHANGELOG.md) - [Commits](https://github.com/hakanaktt/acadrust/compare/v0.6.6...v0.6.8) Updates `log` from 0.4.34 to 0.4.35 - [Release notes](https://github.com/rust-lang/log/releases) - [Changelog](https://github.com/rust-lang/log/blob/main/CHANGELOG.md) - [Commits](https://github.com/rust-lang/log/compare/0.4.34...v0.4.35) Updates `miniz_oxide` from 0.8.9 to 0.9.1 - [Changelog](https://github.com/Frommi/miniz_oxide/blob/master/CHANGELOG.md) - [Commits](https://github.com/Frommi/miniz_oxide/commits) Updates `weezl` from 0.1.12 to 0.2.1 - [Changelog](https://github.com/image-rs/weezl/blob/master/Changes.md) - [Commits](https://github.com/image-rs/weezl/compare/v0.1.12...v0.2.1) Updates `skrifa` from 0.44.0 to 0.48.0 - [Release notes](https://github.com/googlefonts/fontations/releases) - [Changelog](https://github.com/googlefonts/fontations/blob/main/docs/RELEASE.md) - [Commits](https://github.com/googlefonts/fontations/compare/skrifa-v0.44.0...skrifa-v0.48.0) Updates `jixel` from 0.3.4 to 0.5.7 - [Release notes](https://github.com/awxkee/jixel/releases) - [Commits](https://github.com/awxkee/jixel/compare/0.3.4...0.5.7) Updates `encoding_rs` from 0.8.42 to 0.8.44 - [Commits](https://github.com/hsivonen/encoding_rs/compare/v0.8.42...v0.8.44) Updates `crc32fast` from 1.5.2 to 1.5.5 - [Commits](https://github.com/srijs/rust-crc32fast/compare/v1.5.2...v1.5.5) Updates `flate2` from 1.1.10 to 1.1.11 - [Release notes](https://github.com/rust-lang/flate2-rs/releases) - [Changelog](https://github.com/rust-lang/flate2-rs/blob/main/CHANGELOG.md) - [Commits](https://github.com/rust-lang/flate2-rs/compare/1.1.10...v1.1.11) Updates `rustix` from 1.1.5 to 1.1.6 - [Release notes](https://github.com/bytecodealliance/rustix/releases) - [Changelog](https://github.com/bytecodealliance/rustix/blob/main/CHANGES.md) - [Commits](https://github.com/bytecodealliance/rustix/compare/v1.1.5...v1.1.6) Updates `moxcms` from 0.8.1 to 0.9.2 - [Release notes](https://github.com/awxkee/moxcms/releases) - [Commits](https://github.com/awxkee/moxcms/compare/0.8.1...0.9.2) Updates `zip` from 9.1.3 to 9.5.1 - [Release notes](https://github.com/zip-rs/zip2/releases) - [Changelog](https://github.com/zip-rs/zip2/blob/master/CHANGELOG.md) - [Commits](https://github.com/zip-rs/zip2/compare/v9.1.3...v9.5.1) Updates `rfd` from 0.17.2 to 0.18.0 - [Release notes](https://github.com/PolyMeilex/rfd/releases) - [Changelog](https://github.com/PolyMeilex/rfd/blob/master/CHANGELOG.md) - [Commits](https://github.com/PolyMeilex/rfd/compare/0.17.2...0.18.0) Updates `sha1` from 0.10.7 to 0.11.0 - [Commits](https://github.com/RustCrypto/hashes/compare/sha1-v0.10.7...sha1-v0.11.0) Updates `cfb` from 0.15.0 to 0.16.0 - [Commits](https://github.com/mdsteele/rust-cfb/compare/v0.15.0...v0.16.0) Updates `quick-xml` from 0.41.0 to 0.42.0 - [Release notes](https://github.com/tafia/quick-xml/releases) - [Changelog](https://github.com/tafia/quick-xml/blob/master/Changelog.md) - [Commits](https://github.com/tafia/quick-xml/compare/v0.41.0...v0.42.0) Updates `harfrust` from 0.13.3 to 0.16.0 - [Release notes](https://github.com/harfbuzz/harfrust/releases) - [Changelog](https://github.com/harfbuzz/harfrust/blob/main/CHANGELOG.md) - [Commits](https://github.com/harfbuzz/harfrust/compare/0.13.3...0.16.0) Updates `fontique` from 0.11.1 to 0.13.0 - [Release notes](https://github.com/linebender/parley/releases) - [Changelog](https://github.com/linebender/parley/blob/main/CHANGELOG.md) - [Commits](https://github.com/linebender/parley/compare/v0.11.1...v0.13.0) Updates `windows-registry` from 0.6.1 to 0.100.0 - [Release notes](https://github.com/microsoft/windows-rs/releases) - [Commits](https://github.com/microsoft/windows-rs/commits) Updates `write-fonts` from 0.54.1 to 0.56.0 - [Release notes](https://github.com/googlefonts/fontations/releases) - [Changelog](https://github.com/googlefonts/fontations/blob/main/docs/RELEASE.md) - [Commits](https://github.com/googlefonts/fontations/compare/write-fonts-v0.54.1...write-fonts-v0.56.0) Updates `ureq` from 3.5.0 to 3.5.2 - [Changelog](https://github.com/algesten/ureq/blob/main/CHANGELOG.md) - [Commits](https://github.com/algesten/ureq/compare/3.5.0...3.5.2) Updates `skera` from 0.8.0 to 0.10.0 - [Release notes](https://github.com/googlefonts/fontations/releases) - [Changelog](https://github.com/googlefonts/fontations/blob/main/docs/RELEASE.md) - [Commits](https://github.com/googlefonts/fontations/compare/skera-v0.8.0...skera-v0.10.0) Updates `icu_locale_core` from 2.3.0 to 2.4.0 - [Release notes](https://github.com/unicode-org/icu4x/releases) - [Changelog](https://github.com/unicode-org/icu4x/blob/main/CHANGELOG.md) - [Commits](https://github.com/unicode-org/icu4x/compare/icu@2.3.0...icu@2.4.0) Updates `icu_provider` from 2.3.1 to 2.4.0 - [Release notes](https://github.com/unicode-org/icu4x/releases) - [Changelog](https://github.com/unicode-org/icu4x/blob/main/CHANGELOG.md) - [Commits](https://github.com/unicode-org/icu4x/compare/icu@2.3.1...icu@2.4.0) Updates `icu_provider_blob` from 2.3.0 to 2.4.0 - [Release notes](https://github.com/unicode-org/icu4x/releases) - [Changelog](https://github.com/unicode-org/icu4x/blob/main/CHANGELOG.md) - [Commits](https://github.com/unicode-org/icu4x/compare/icu@2.3.0...icu@2.4.0) Updates `jpeg-encoder` from 0.6.1 to 0.7.1 - [Release notes](https://github.com/vstroebel/jpeg-encoder/releases) - [Commits](https://github.com/vstroebel/jpeg-encoder/compare/v0.6.1...v0.7.1) Updates `hayro-jpeg2000` from 0.3.5 to 0.5.0 - [Release notes](https://github.com/LaurenzV/hayro/releases) - [Commits](https://github.com/LaurenzV/hayro/compare/hayro-jpeg2000-v0.3.5...hayro-jpeg2000-v0.5.0) Updates `tokio` from 1.53.2 to 1.54.1 - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.53.2...tokio-1.54.1) Updates `getrandom` from 0.3.4 to 0.4.3 - [Changelog](https://github.com/rust-random/getrandom/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-random/getrandom/compare/v0.3.4...v0.4.3) Updates `pgp` from 0.21.0 to 0.21.1 - [Release notes](https://github.com/rpgp/rpgp/releases) - [Changelog](https://github.com/rpgp/rpgp/blob/main/CHANGELOG.md) - [Commits](https://github.com/rpgp/rpgp/compare/v0.21.0...v0.21.1) --- updated-dependencies: - dependency-name: acadrust dependency-version: 0.6.8 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-dependencies - dependency-name: cfb dependency-version: 0.16.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: crc32fast dependency-version: 1.5.5 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-dependencies - dependency-name: encoding_rs dependency-version: 0.8.44 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-dependencies - dependency-name: flate2 dependency-version: 1.1.11 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-dependencies - dependency-name: fontique dependency-version: 0.13.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: getrandom dependency-version: 0.4.3 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: harfrust dependency-version: 0.16.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: hayro-jpeg2000 dependency-version: 0.5.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: icu_locale_core dependency-version: 2.4.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: icu_provider dependency-version: 2.4.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: icu_provider_blob dependency-version: 2.4.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: jixel dependency-version: 0.5.7 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: jpeg-encoder dependency-version: 0.7.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: log dependency-version: 0.4.35 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-dependencies - dependency-name: miniz_oxide dependency-version: 0.9.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: moxcms dependency-version: 0.9.2 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: pgp dependency-version: 0.21.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-dependencies - dependency-name: quick-xml dependency-version: 0.42.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: rfd dependency-version: 0.18.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: rustix dependency-version: 1.1.6 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-dependencies - dependency-name: sha1 dependency-version: 0.11.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: skera dependency-version: 0.10.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: skrifa dependency-version: 0.48.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: tokio dependency-version: 1.54.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: ureq dependency-version: 3.5.2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-dependencies - dependency-name: weezl dependency-version: 0.2.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: windows-registry dependency-version: 0.100.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: write-fonts dependency-version: 0.56.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies - dependency-name: zip dependency-version: 9.5.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
craft-xml
Bounded XML for hostile input: an owned element tree, streaming of repeated elements, a pull reader, escaping and a writer. It replaces the small XML helper each Craft app carried.
It is built on quick-xml's tokenizer (MIT). Everything above the tokens is here: limits,
references, namespaces, recovery, the tree and the writer.
use craft_xml::{Local, Options};
let root = craft_xml::parse(b"<p:sp id='5'><p:t>one & two</p:t></p:sp>").unwrap();
assert_eq!(root.attr_u32("id"), Some(5));
assert_eq!(root.child(Local("t")).map(|t| t.deep_text()).as_deref(), Some("one & two"));
// Rows go to the callback one at a time; the tree keeps the rest.
let part = b"<sheetData><row r='1'/><row r='2'/></sheetData>";
let mut rows = 0;
let sheet = Options::local().parse_streaming(part, &["row"], |row| {
rows += row.attr_u32("r").unwrap_or(0);
Ok::<(), craft_xml::Error>(())
});
assert_eq!((rows, sheet.map(|s| s.children.len())), (3, Ok(0)));
Reading
parse(bytes) reads with Options::default(). Options is a plain struct; set what differs.
| Option | Default | Meaning |
|---|---|---|
limits |
see below | What the reader refuses to exceed. |
names |
AsWritten |
AsWritten keeps p:sp. Local keeps sp. Canonical(&c) rewrites to the caller's prefix for the namespace URI. |
ns_decls |
true |
Keep xmlns declarations as attributes. Options::local() and Options::canonical(..) turn it off. |
strict |
false |
See below. .strict() also makes an undefined entity an error. |
unknown_entity |
Drop |
Drop, Literal (keep &name; as text) or Error. |
doctype |
Ignore |
Ignore, RejectInternalSubset or Reject. Never processed, whichever is chosen. |
cdata, pis, comments |
false |
Keep these as their own nodes. CDATA content is otherwise joined to the text around it. |
drop_blank_text |
false |
Drop the text of an element with child elements when all of it is whitespace (indentation). |
split_depth |
2 |
For streaming: how far below the root an element may be and still be handed out. |
Limits
| Limit | Default | Error |
|---|---|---|
max_input |
256 MiB | TooLarge |
max_depth |
256 levels (the root is 1) | TooDeep |
max_nodes |
2,000,000 nodes kept in the tree: elements, text stretches, kept CDATA, instructions and comments | TooManyNodes |
max_attrs |
1024 on one start tag, namespace declarations and malformed ones included; with canonical names or strict reads, also the declarations in scope at once | TooManyAttrs |
max_attrs_total |
4,000,000 attributes kept in the tree, over all its elements | TooManyAttrsTotal |
A limit exceeded is an error, never a panic and never a truncated tree. parse_streaming_partial
returns the error together with what had been read, for a caller that wants the part's other
children when its rows cannot all be read; that tree is marked as partial by the error beside it. Elements handed to a
streaming callback leave the node and attribute counts, so a streamed part may be of any length. Text is not
counted separately: nothing expands, so it is never more than three times the input (the worst
case is input that is not UTF-8, where each bad byte becomes U+FFFD).
What is never done
- No DTD processing. A
<!DOCTYPE>is skipped or refused; its entity and element declarations are not read. - No entity expansion beyond
&<>"'and numeric character references. A reference to a declared entity is an undefined entity. Nothing external is ever fetched. - No validation, no XPath, no XInclude, no schema.
- No encodings other than UTF-8 and UTF-16. The encoding an XML declaration names is not consulted.
- Names are not checked on reading. The writer checks them (below).
Lenient and strict
A lenient read keeps what a damaged document had:
- an end tag closes the innermost open element, whatever its name; an end tag with nothing open is skipped;
- elements still open at the end of the input are closed (a truncated part);
- reading stops when the root element ends: nothing after it is looked at;
- a malformed attribute is skipped; bytes that are not UTF-8 become U+FFFD.
A strict read rejects duplicate raw or expanded attribute names (while allowing undeclared prefixes in fragments). It makes each of those an error, and also a second root element and text outside the
root, in the pull reader as in the tree. Markup the tokenizer cannot read (<a b='1, an unterminated comment) is an error either
way. A lenient read keeps repeated attributes.
Text
- Literal CR LF and CR in text and CDATA are read as LF (XML 1.0 §2.11).
stays a CR. - Literal tab, LF and CR in an attribute value are read as spaces. Character references stay.
- A numeric reference to a character XML 1.0 cannot carry (
�,, a surrogate) is an undefined entity. - UTF-16 is recognised by its byte-order mark, or without one by the zero bytes of its first two characters. An unpaired surrogate becomes U+FFFD, also in a strict read.
Namespaces
Canonical { namespaces: &[(prefix, uri)], unknown, element, attr_value }:
- an element in a listed namespace is
prefix:local; in an unlisted one,unknown:local(?:localby default); in none, or with a prefix nothing declares,local; - a prefixed attribute likewise; an unprefixed attribute keeps its name;
xml:needs no entry;elementoverrides the prefix by element and parent;attr_valuerewrites a value that holds prefixes while the scope is known (Scope::uri).
? cannot be part of an XML name, so the writer leaves unknown-namespace elements and attributes out.
The tree
El { name, attrs: Vec<(String, String)>, children: Vec<Node> }, Node::{El, Text, CData, Pi, Comment}. Fields are public.
Where the apps disagreed, there are two spellings, not one behaviour:
| Question | Spellings | Which app used which |
|---|---|---|
| Is a name matched whole or by local part? | child("w:p") / child(Local("p")). Every method that takes a name takes either: child, children, path, find, find_all, child_attr, child_text, child_mut, is, first_start. |
Whole: WordCraft, GridCraft, LightCraft, AniCraft. Local: DeckCraft, DesignCraft. |
| How is an attribute looked up? | attr (the exact name). attr_or_plain("w:val") (exact, else the unprefixed val). attr_local("id") (exact, else any prefix; attr_local("r:id") is any prefixed id). |
attr: GridCraft, DesignCraft, LightCraft, AniCraft. attr_or_plain: WordCraft. attr_local: DeckCraft. |
Does text include descendants? |
text() is the element's own text and CDATA. deep_text() adds every descendant's. |
Own: WordCraft text, GridCraft and LightCraft .text. Deep: DeckCraft text, DesignCraft text_content, WordCraft deep_text. |
| Is a number read exactly? | attr_u32, attr_i32, attr_i64, attr_f64 read exactly (value::to_*). value::to_i64_lossy, to_i32_lossy, to_u32_lossy truncate a fraction and clamp. |
Exact: GridCraft, AniCraft. Lossy: DeckCraft. |
Booleans (attr_bool, flag, value::to_bool): 1, true, on, t and 0, false, off,
f, trimmed, case-sensitive. That is GridCraft's set; DeckCraft's lacks t/f and IDML only
writes true/false, so both are covered. attr_f64 is finite values only, as in every app.
descendants, find, find_all, deep_text, node_count and the writer do not recurse.
node_count() is what max_nodes counted for an element. A reader of a package of many parts
keeps one budget with it: charge each tree it keeps, and read the next part with what is left as
max_nodes, so a part over the budget stops before its tree is built.
Writing
esc,push_esc: text.&,<,>escaped; CR written .esc_attr,push_esc_attr: a double-quoted attribute value. Also", and tab, LF, CR as	 .- Both drop characters XML 1.0 cannot carry (
is_xml_char). El::to_xml,write_xml: one line.El::to_xml_pretty(indent),write_xml_pretty: an element whose children are all elements has them one per line; any other element is on one line exactly asto_xmlwrites it.- An element or attribute whose name is not an XML name (
is_name) is not written, with everything inside it. A name can never inject markup. Writer:Writer::document()(with thestandalone="yes"declaration),Writer::new()(a fragment),Writer::pretty(indent);decl,doctype,pi;tag(name).attr(k, v).attr_opt(k, v).open()/.empty()/.text(t);open,empty,leafwith a slice of attributes;close()(the writer knows the name);text,cdata,raw,tree;finishcloses what is open.
Round trip
Reading what to_xml wrote gives an equal tree. Reading a document and writing it keeps the
elements, attributes in order, text, and with the options on, CDATA sections, processing
instructions and comments. It does not keep:
- the XML declaration, the DOCTYPE, and anything outside the root element;
- quoting and spacing inside tags, and how a character was written (
AagainstA); <a></a>against<a/>;- comments, processing instructions and CDATA sections as sections, unless the options keep them;
- a literal CR; literal tab, LF and CR in attribute values (they were read as spaces);
- with
to_xml_pretty, whitespace-only text between the children of an element-only element; - namespace declarations, when names are read as
LocalorCanonical.
Migration
WordCraft crates/docx/src/xml.rs
| WordCraft | craft-xml |
|---|---|
MAX_DEPTH, MAX_ELEMENTS, MAX_ATTRS |
Limits. max_nodes counts text nodes too: use twice the element count. |
NAMESPACES, OTHER_NAMESPACES, STRICT, prefix_for |
The tables stay in WordCraft, as Canonical::namespaces; Canonical::prefix. |
element_prefix, drawing_prefix |
Canonical::element. The rules stay in WordCraft. |
requirement_prefix and the Requires rewrite |
Canonical::attr_value with Scope::uri. |
parse, parse_ns(extra), parse_strict |
Options::canonical(&c).parse; extra entries first in the table; .strict(). |
Node, El { name, attrs, kids } |
Node, El { name, attrs, children } |
attr |
attr_or_plain |
els, child, children, find, deep_text, local, to_xml |
elements, then the same names |
text |
text (a Cow) |
child_val(n) |
child(n).and_then(|c| c.attr_or_plain("w:val")) |
utf16_to_utf8 |
to_utf8 |
esc |
esc for text, esc_attr for attribute values |
W::new, open, empty, leaf, text, raw, into_bytes |
Writer::document, then the same names |
W::close(name), W::val(name, v), w.s |
close(), empty(name, &[("w:val", v)]), as_str() |
is_rel_attr, REL_*, DECORATIVE_*, body_ns |
Stay in WordCraft. |
GridCraft crates/xlsx/src/xml.rs
| GridCraft | craft-xml |
|---|---|
MAX_DEPTH, MAX_XML_NODES |
Limits |
parse |
Options { unknown_entity: Literal, ..Options::local() }.parse |
parse_streaming(xml, split, cb) |
.parse_streaming(xml, split, cb); cb returns any error that is From<craft_xml::Error> |
first_start(xml, name) |
Options::local().first_start(xml, name) |
El.children (elements), El.text |
elements(), text() |
attr, attr_u32, attr_i64, attr_f64, attr_bool, flag, child, path |
The same names |
kids(n), child_val(n) |
children(n), child_attr(n, "val") |
to_utf8, esc, push_esc, esc_attr |
The same names |
push_u64, push_a1, num, push_num, rich_text, phonetic_data, encode_xstring, decode_xstring, t_el, si_body |
Stay in GridCraft. |
DeckCraft crates/pptx/src/xml.rs
| DeckCraft | craft-xml |
|---|---|
MAX_DEPTH, MAX_NODES |
Limits |
parse(bytes)?.root, Doc::ns_decls |
craft_xml::parse(bytes)?, root.ns_decls() (prefix and URI) |
attr(n), has_attr(n) |
attr_local(n), attr_local(n).is_some() |
i64(n), i32(n), u32(n) |
attr_local(n).and_then(value::to_i64_lossy) and to_i32_lossy, to_u32_lossy |
f64(n), bool(n) |
attr_local(n).and_then(value::to_f64) and to_bool |
is(l), child(l), children_named(l), path(ls), find(l) |
is(Local(l)), child(Local(l)), children(Local(l)), path(&[Local(..)]), find(Local(l)) |
find_all(l, &mut out) |
out.extend(e.find_all(Local(l))) |
text() |
deep_text() |
child_val(l) |
child(Local(l)).and_then(|c| c.attr_local("val")) |
local, prefix, set_attr, elements, elements_mut, to_xml, esc, esc_attr |
The same names |
W::new, W::frag, finish |
Writer::document, Writer::new, into_bytes |
A::new().a(k, v), .o(k, opt) |
tag(name).attr(k, v), .attr_opt(k, opt) |
A::b(k, opt_bool), A::t(k, bool) |
.attr_opt(k, opt.map(u8::from)), .attr_opt(k, flag.then_some(1)) |
open(name, a), open0, empty(name, a), empty0 |
tag(name)….open() / .empty(), or open(name, &[]), empty(name, &[]) |
close(name), val(name, v), elt(name, t) |
close(), tag(name).attr("val", v).empty(), leaf(name, &[], t) |
DesignCraft crates/idml/src/xml.rs, crates/pptx/src/xml.rs, crates/engine/src/cmd/xml.rs
| DesignCraft | craft-xml |
|---|---|
parse |
Options { strict: true, pis: true, ..Options::default() }.parse |
Node::Pi(target, content) |
Node::Pi { target, data } |
El::new(n).attr(k, v).child(c).text(t) |
El::new(n).with_attr(k, v).with_child(c).with_text(t) |
set, push, get, local, elements |
set_attr, push, attr, local, elements |
find(l), find_all(l) (direct children) |
child(Local(l)), children(Local(l)) |
text_content |
deep_text |
write(out, depth) |
write_xml_pretty(out, "\t") |
escape_into(out, s, attr) |
push_esc(out, s), push_esc_attr(out, s) |
document(root), document_with_pi(root, pi) |
Writer::pretty("\t"), then decl(true), pi(target, data) or raw(pi), tree(root), into_bytes() |
prop, prop_el, num, boolean (IDML's <Properties> form) |
Stay in DesignCraft, on attr and child. |
pptx esc |
esc for text, esc_attr for attribute values. emu, emu_len, angle, pct, hex stay. |
cmd esc, valid_name |
esc/esc_attr; is_name (which also accepts :). The rest is the app's structure commands and stays. |
The others
| App helper | craft-xml |
|---|---|
WordCraft formats/src/odt/xml.rs: events, events_at, Ev, Attrs, get, local |
Options::events(utf8), Events::next, Events::span, Event. Event::End names the start tag. An error is returned, not swallowed. length stays. |
AniCraft crates/xml: parse |
Options { strict: true, drop_blank_text: true, unknown_entity: Literal, ..Options::default() }.parse |
AniCraft parse_mixed, TEXT_NODE |
Not needed: text nodes keep their place among the children. |
AniCraft Element::attr, u32, child, f32, list(n) |
attr, attr_u32, child, attr_f64(n) as f32, child(n) then elements() |
LightCraft lensdb/src/xml.rs: parse, Node, attr, num, kids, kid, kid_text, entity, unescape |
Options::parse with its limits (max_depth: 32), El, attr, attr_f64, children, child, child_text (trim it), entity, unescape |
FilmCraft interchange/src/xml.rs: escape, escape_attr, XmlWriter |
esc, esc_attr, Writer::pretty(" ") with decl(false) and doctype(name); text_attrs is leaf |
FilmCraft parse, child, children, elements, text, path_text, child_text, child_i64, child_f64 |
Options { doctype: RejectInternalSubset, .. }.parse and the tree's child, children, elements, text, path, child_text, value::to_i64_lossy, value::to_f64. The result is an El, not a roxmltree::Document. |
FigCraft vectordrawable/src/xml.rs: esc |
esc_attr |
MailCraft dav, ews readers |
Options { doctype: Reject, .. }.strict(), with Canonical for the DAV and EWS namespaces |
Behaviour that changes on migration
- Bytes written.
escno longer escapes quotes in text; WordCraft, FilmCraft, FigCraft and DesignCraft's pptx writer escaped'and this crate never does (values are double-quoted); DesignCraft's IDML writer wrote	where this writes	, and wrote a literal CR in text where this writes . All read back the same, except the CR, which now survives. - Bytes that are not UTF-8 in text were an error in WordCraft, GridCraft and DesignCraft's lenient readers. Here a lenient read replaces them and a strict read refuses them.
- GridCraft kept an attribute value raw when it held an undefined entity; here the rest of the value is still resolved. It did not normalise line ends in CDATA; here they are.
- DeckCraft kept reading after the root element and could fail on what followed; a lenient read here stops.
- Node counts include text, so an element limit becomes about twice the number.
- LightCraft did not normalise literal tabs and line ends in attribute values to spaces; here they are.
- FilmCraft rounded a fractional
child_i64;value::to_i64_lossytruncates. Itschild_f64acceptedNaNand infinities;value::to_f64does not. - AniCraft kept attributes in a map (the last of a repeated name won); here they are a list and
attrreturns the first.
Left to the apps
- FigCraft's
Outlayout (one attribute per line, as Android Studio formats drawables). - EffectCraft's
xml_project.rs: a project codec with its own reader. It writes control characters as&#N;, which XML 1.0 forbids and this crate does not read. - VectorCraft's
xml_id.rs: object names as XML IDs (_xHH_escapes), a naming rule and not XML syntax. - PhotoCraft's
io/src/xml.rsand FilmCraft'sparseguardroxmltreeand return its document. Code that moves toElgets the same guards fromLimitsandDoctype; code that stays onroxmltreekeeps its guard. - Booleans that are not
xsd:boolean: FilmCraft'sTRUE/FALSE, AniCraft's "anything buttrueis false". - Number formatting (
num), units, colours, and every format's own vocabulary.