opml 1.0.1

An OPML parser for Rust.
Documentation

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 opml::{OPML, Outline};

let xml = r#"<opml version="2.0"><head/><body><outline text="Outline"/></body></opml>"#;
let parsed = OPML::new(xml).unwrap();

let mut expected = OPML::default();
expected.body.outlines.push(Outline {
text: "Outline".to_string(),
..Outline::default()
});

println!("{:#?}", parsed);
assert_eq!(parsed, expected);

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 opml::{Head, OPML};

let mut opml = OPML::default();
opml.head = Some(Head {
title: Some("Rust Feeds".to_string()),
..Head::default()
});
opml
.add_feed("Rust Blog", "https://blog.rust-lang.org/feed.xml")
.add_feed(
"Inside Rust",
"https://blog.rust-lang.org/inside-rust/feed.xml",
);

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!("{}", xml);
assert_eq!(xml, expected);