1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
//! Collection of utilities for working with XML

use std::str;

use anyhow::anyhow;
use sxd_document::*;

/// Parses a vector of bytes into a XML document
pub fn parse_bytes(bytes: &[u8]) -> anyhow::Result<Package> {
  let string = str::from_utf8(bytes)?;
  match parser::parse(string) {
    Ok(doc) => Ok(doc),
    Err(err) => Err(anyhow!("Failed to parse bytes as XML - {}", err))
  }
}