This crate provides an API to parse and construct OPML documents to and from regular Rust structs.
Getting Started
Parsing
Parsing XML into an OPML struct can be done with
OPML::new()
. Resulting in an error if the
XML can't be parsed, if the included OPML version is not supported
(currently all OPML versions (1.0, 1.1 and 2.0) are supported) or if the
Body element contains no child
Outline elements,
as per the spec.
use ;
let xml = r#"<opml version="2.0"><head/><body><outline text="Outline"/></body></opml>"#;
let parsed = OPML new.unwrap;
let mut expected = OPML default;
expected.body.outlines.push;
println!;
assert_eq!;
Constructing
Constructing OPMLs is very easy as all you have to do is instantiate the
OPML struct with
OPML::default()
, add anything wanted
and then call OPML::to_xml()
to return
the XML as a string.
use ;
let mut opml = OPML default;
opml.head = Some;
opml
.add_feed
.add_feed;
let xml = opml.to_xml.unwrap;
let expected = r#"<opml version="2.0"><head><title>Rust Feeds</title></head><body><outline text="Rust Blog" xmlUrl="https://blog.rust-lang.org/feed.xml"/><outline text="Inside Rust" xmlUrl="https://blog.rust-lang.org/inside-rust/feed.xml"/></body></opml>"#;
println!;
assert_eq!;