version: 1.1.10 date: 2020-06-01 authors: Luciano Bestia
reader for microXml - the simplified subset of xml
There are many xml parsers/readers/tokenizers/lexers around, but I need something very small and simple for my simple html templates in wasm.\ I found the existence of a standard (or W3C proposal) for MicroXml - dramatically simpler then the full Xml standard. Perfect for my use-case: I have small simple html files, that are microXml compatible.
MicroXML is a subset of XML. It is dramatically simpler.\ https://www.xml.com/articles/2017/06/03/simplifying-xml-microxml/\ https://dvcs.w3.org/hg/microxml/raw-file/tip/spec/microxml.html\ MicroXML is actually well-formed Xml.\ In the data model of MicroXml there are no CData, namespaces, declarations, processing instructions,...\ An example of all can be done in a well-formed microXml:
xml
<memo lang="en" date="2017-05-01">
I <em>love</em> microXML!<br />
<!-- some comment -->
It's so clean & simple.
</memo>
MicroXml can be only in utf-8. I am lucky, because Rust Strings are internally utf-8 and are automatically checked for correctness.\ MicroXml should go through normalization: CR & CRLF should be converted to LF, but I don't do that here. Also decoding xml control characters ", &,... or decoding unicode encodings like , ,... is not inside the reader. This is left for a higher library to choose what to do with it.\ MicroXml can contain Comments, but they are not official microXml data. But I need them for my templating project.\ Whitespaces are completely preserved in Text Nodes. For me they are significant. Also newline and Tabs. This is different from full Xml whitespace processing.\ All other whitespaces are ignored - they are insignificant.
This ReaderForMicroXml obviously cannot read a complicated full XML.\
This reader_for_microxml
is used for small html fragments.\
They must be well-formed microXml.\
This fragments are meant for a html templating for dodrio.\
Because of the small size of fragments, I can put all the text in memory in a string.\
Only basic mal-formed incorrectness produce errors. I am not trying to return errors for all the possible mal-formed incorrectness in microXml.\
The speed is not really important, but the size of the code is, because it will be used in WebAssembly. Every code is too big for Wasm!\
The crate has #![no_std]
, NO dependencies, NO allocations, .
The reader is an iterator.\
It implements the trait of the iterator.\
Use this syntax to process all tokens:\
for result_token in reader_iterator {
\
or\
let x: Option<Result<Token, &str>> = reader_iterator.next();
The speed could probably be improved if I use Vec\
Run the tests with:\
clear; cargo make test
Find examples in the repository on github.\
Run them with:
clear; cargo make run_rel1
\
clear; cargo make run_rel2
\
it is a shortcut to:\
cargo run --example microxml_tree examples/t2.html
```rust /// read xml and write to screen use readerformicroxml::*;
fn main(){ let strxml = r#"test"#; let mut readeriterator = ReaderForMicroXml::new(strxml); let result = readxmltodebugstring(&mut readeriterator); println!("Result: {}", result) }
fn readxmltodebugstring(readeriterator: &mut ReaderForMicroXml) -> String {
let mut result = String::new();
// readeriterator is iterator Option
It is recommended to always use cargo-crev\ to verify the trustworthiness of each of your dependencies.\ Please, spread this info.\ On the web use this url to read crate reviews. Example:\ https://bestia.dev/cargo_crev_web/query/num-traits
https://dvcs.w3.org/hg/microxml/raw-file/tip/spec/microxml.html\ https://www.xml.com/articles/2017/06/03/simplifying-xml-microxml/\ https://github.com/tafia/quick-xml\ https://github.com/RazrFalcon/roxmltree