Crate rio_xml[][src]

Implementation of an RDF XML streaming parser.

How to read a file foo.rdf and count the number of rdf:type triples:

use rio_xml::{RdfXmlParser, RdfXmlError};
use rio_api::parser::TriplesParser;
use rio_api::model::NamedNode;
use std::io::BufReader;
use std::fs::File;
use oxiri::Iri;

let rdf_type = NamedNode { iri: "" };
let mut count = 0;
RdfXmlParser::new(BufReader::new(File::open("foo.rdf")?), Some(Iri::parse("file:foo.rdf".to_owned()).unwrap())).parse_all(&mut |t| {
    if t.predicate == rdf_type {
        count += 1;
    Ok(()) as Result<(), RdfXmlError>

Write some triples in RDF XML into a Vec buffer:

use rio_xml::RdfXmlFormatter;
use rio_api::formatter::TriplesFormatter;
use rio_api::model::{NamedNode, Triple};

let mut formatter = RdfXmlFormatter::new(Vec::default())?;
formatter.format(&Triple {
    subject: NamedNode { iri: "" }.into(),
    predicate: NamedNode { iri: "" }.into(),
    object: NamedNode { iri: "" }.into()
let _xml = formatter.finish()?;

Sophia adapters for Rio parsers are provided if the sophia feature is enabled.



Error that might be returned during parsing.


A RDF XML formatter.


A RDF XML streaming parser.