• Home
  • Raw
  • Download

Lines Matching +full:- +full:- +full:xml

1 xml-rs, an XML library for Rust
4 [![CI](https://github.com/kornelski/xml-rs/actions/workflows/main.yml/badge.svg)](https://github.co…
5 [![crates.io][crates-io-img]](https://lib.rs/crates/xml-rs)
6 [![docs][docs-img]](https://docs.rs/xml-rs/)
8 [Documentation](https://docs.rs/xml-rs/)
10 [crates-io-img]: https://img.shields.io/crates/v/xml-rs.svg
11 [docs-img]: https://img.shields.io/badge/docs-latest%20release-6495ed.svg
13 xml-rs is an XML library for the [Rust](https://www.rust-lang.org/) programming language.
14 It supports reading and writing of XML documents in a streaming fashion (without DOM).
18 * XML spec conformance better than other pure-Rust libraries.
22 * Support for UTF-16, UTF-8, ISO-8859-1, and ASCII encodings.
27 The API is heavily inspired by Java Streaming API for XML ([StAX][stax]). It contains a pull parser…
33 writer events easily, and so it is possible to write XML transformation chains in a pretty
36 This parser is mostly full-featured, however, there are limitations:
37 * Legacy code pages and non-Unicode encodings are not supported;
39 * attribute value normalization is not performed, and end-of-line characters are not normalized eit…
41 Other than that the parser tries to be mostly XML-1.1-compliant.
43 Writer is also mostly full-featured with the following limitations:
44 * no support for encodings other than UTF-8,
47 or comments are well-formed.
50 ------------------
52 xml-rs uses [Cargo](https://crates.io), so add it with `cargo add xml` or modify `Cargo.toml`:
56 xml = "0.8.16"
59 The package exposes a single crate called `xml`.
61 Reading XML documents
62 ---------------------
64 [`xml::reader::EventReader`](EventReader) requires a [`Read`](stdread) instance to read from. It ca…
66 [EventReader]: https://docs.rs/xml-rs/latest/xml/reader/struct.EventReader.html
67 [stdread]: https://doc.rust-lang.org/stable/std/io/trait.Read.html
75 use xml::reader::{EventReader, XmlEvent};
77 fn main() -> std::io::Result<()> {
78 let file = File::open("file.xml")?;
90 depth -= 1;
91 println!("{:spaces$}-{name}", "", spaces = depth * 2);
97 // There's more: https://docs.rs/xml-rs/latest/xml/reader/enum.XmlEvent.html
120 error or end-of-document event once and will produce `None` afterwards.
122 It is also possible to tweak parsing process a little using [`xml::reader::ParserConfig`][ParserCon…
125 [ParserConfig]: https://docs.rs/xml-rs/latest/xml/reader/struct.ParserConfig.html
129 statistics about specified XML document. It can also be used to check for well-formedness of
130 XML documents - if a document is not well-formed, this program will exit with an error.
137 You should also set a maximum document size via `io::Read`'s [`take(max)`](https://doc.rust-lang.or…
139 Writing XML documents
140 ---------------------
142 xml-rs also provides a streaming writer much like StAX event writer. With it you can write an
143 XML document to any `Write` implementor.
147 use xml::writer::{EmitterConfig, XmlEvent};
149 /// A simple demo syntax where "+foo" makes `<foo>`, "-foo" makes `</foo>`
150 fn make_event_from_line(line: &str) -> XmlEvent {
154 } else if line.starts_with("-") {
161 fn main() -> io::Result<()> {
188 The library provides an XML event building DSL which helps to construct complex events,
203 There are more examples in [`xml::writer::XmlEvent`][XmlEvent] documentation.
205 [XmlEvent]: https://docs.rs/xml-rs/latest/xml/reader/enum.XmlEvent.html
210 [EmitterConfig]: https://docs.rs/xml-rs/latest/xml/writer/struct.EmitterConfig.html
213 ------------
215 Please report issues at: <https://github.com/kornelski/xml-rs/issues>.