#![forbid(unsafe_code)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "alloc")]
extern crate alloc;
pub mod alloc_prelude;
pub mod document;
pub mod dtd;
pub mod entity;
pub mod error;
pub mod io;
pub mod namespace;
pub mod node;
pub mod options;
pub mod parser;
pub mod stringify;
pub mod validator;
pub mod xpath;
pub mod xsd;
use crate::alloc_prelude::*;
pub use document::Document;
pub use dtd::{DtdAttributeRule, DtdElementRule, DtdValidator, ExternalSubsetResolver};
pub use entity::{EntityMapper, EntityResolver};
pub use error::{Result, XmlError};
pub use io::{
DestinationExt, Format, IByteStream, ICharStream, IClearable, IDestination, IPositionAware,
IRewindable, ISource, XmlDestination, XmlSource,
};
pub use namespace::{Namespace, NamespaceScope, QName};
pub use node::{Attribute, DeclarationData, DocTypeData, NodeData, NodeId, NodeKind};
pub use options::ParseOptions;
pub use parser::{XmlParser, XmlPullAttribute, XmlPullEvent, XmlPullParser};
pub use stringify::{
CanonicalOptions, CanonicalSerializer, SerializeOptions, XmlSerializer, canonicalize,
canonicalize_to, canonicalize_to_with_options, stringify_to, stringify_to_with_options,
};
#[cfg(feature = "format-converters")]
pub use stringify::{
to_bencode, to_bencode_bytes, to_json, to_json_string, to_toml, to_toml_string, to_yaml,
to_yaml_string,
};
pub use validator::XmlValidator;
pub use xpath::{XPathEngine, XPathValue};
pub use xsd::{
Compositor, XsdAttributeRule, XsdComplexType, XsdElementRule, XsdRestriction, XsdValidator,
};
#[cfg(feature = "serde")]
pub mod serde_impl;
#[cfg(feature = "serde")]
pub use serde_impl::{
from_str as from_xml_str, to_string as to_xml_string,
to_string_with_root as to_xml_string_with_root,
};
pub fn parse(xml: &str) -> Result<Document> {
parse_with_options(xml, ParseOptions::default())
}
pub fn parse_with_options(xml: &str, options: ParseOptions) -> Result<Document> {
let source = XmlSource::from_string(xml);
let mut parser = XmlParser::new(source, options);
parser.parse()
}
pub fn parse_bytes(bytes: &[u8]) -> Result<Document> {
let source = XmlSource::from_bytes(bytes)?;
let options = ParseOptions::default();
let mut parser = XmlParser::new(source, options);
parser.parse()
}
pub fn parse_bytes_with_encoding(bytes: &[u8], encoding: &str) -> Result<Document> {
let source = XmlSource::from_bytes_with_encoding(bytes, encoding)?;
let options = ParseOptions::default();
let mut parser = XmlParser::new(source, options);
parser.parse()
}
#[cfg(feature = "std")]
pub fn parse_reader<R: std::io::Read>(reader: R) -> Result<Document> {
let source = XmlSource::from_reader(reader)?;
let options = ParseOptions::default();
let mut parser = XmlParser::new(source, options);
parser.parse()
}
pub fn parse_source(source: &mut dyn ISource) -> Result<Document> {
parse_source_with_options(source, ParseOptions::default())
}
pub fn parse_source_with_options(
source: &mut dyn ISource,
options: ParseOptions,
) -> Result<Document> {
let xml_source = XmlSource::from_source(source);
let mut parser = XmlParser::new(xml_source, options);
parser.parse()
}
#[inline]
pub fn from_str(xml: &str) -> Result<Document> {
parse(xml)
}
#[inline]
pub fn from_bytes(bytes: &[u8]) -> Result<Document> {
parse_bytes(bytes)
}
#[inline]
pub fn from_source(source: &mut dyn ISource) -> Result<Document> {
parse_source(source)
}
pub fn stringify(doc: &Document) -> String {
XmlSerializer::serialize_to_string(doc, &SerializeOptions::default())
}
#[inline]
pub fn to_string(doc: &Document) -> String {
stringify(doc)
}
#[inline]
pub fn to_vec(doc: &Document) -> Vec<u8> {
stringify(doc).into_bytes()
}
#[cfg(feature = "std")]
pub fn parse_file(path: impl AsRef<std::path::Path>) -> Result<Document> {
parse_file_with_options(path, ParseOptions::default())
}
#[cfg(feature = "std")]
pub fn parse_file_with_options(
path: impl AsRef<std::path::Path>,
options: ParseOptions,
) -> Result<Document> {
let source = XmlSource::from_file(path)?;
let mut parser = XmlParser::new(source, options);
parser.parse()
}
pub mod engine;
pub use engine::XmlEngine;