1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
// Old Push API
// pub trait SAXAttributes {
// fn get_length(&self) -> usize;
// // Need for boxing https://doc.rust-lang.org/book/trait-objects.html
// fn iter(&self) -> Box<dyn Iterator<Item = Box<dyn SAXAttribute>>>;
// // fn get_by_qualified_name(&mut self, index: usize) -> Option<Attribute>;
// // when using trait as object use box otherwise:
// // the trait `std::marker::Sized` is not implemented for `sax::SAXAttribute + 'static`
// fn get_by_index(&self, index: usize) -> Option<Box<dyn SAXAttribute>>;
// }
// pub trait SAXAttribute {
// // fn get_index() -> usize;
// fn get_value(&self) -> &str;
// fn get_local_name(&self) -> &str;
// fn get_qualified_name(&self) -> &str;
// fn get_uri(&self) -> &str;
// }
// pub trait ContentHandler {
// fn start_document(&mut self);
// fn end_document(&mut self);
// fn start_element(
// &mut self,
// uri: &str,
// local_name: &str,
// qualified_name: &str,
// attributes: &dyn SAXAttributes,
// );
// fn end_element(&mut self, uri: &str, local_name: &str, qualified_name: &str);
// fn characters(&mut self, characters: &str);
// //fn start_prefix_mapping(&mut self, prefix: &str , uri: &str);
// //fn end_prefix_mapping(&mut self, prefix: &str , uri: &str);
// }
// pub trait StatsHandler {
// fn offset(&mut self, offset: usize);
// }
//ErrorHandler
// Pull API
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Attribute<'a> {
pub value: &'a str,
pub name: &'a str,
// namespace aware
pub local_name: &'a str,
pub prefix: &'a str,
pub namespace: &'a str,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct StartElement<'a> {
pub name: &'a str,
pub attributes: Vec<Attribute<'a>>,
pub is_empty: bool,
// namespace aware
pub local_name: &'a str,
pub prefix: &'a str,
pub namespace: &'a str,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EndElement<'a> {
pub name: &'a str,
// namespace aware
pub local_name: &'a str,
pub prefix: &'a str,
pub namespace: &'a str,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Reference<'a> {
pub raw: &'a str,
pub resolved: Option<&'a str>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Event<'a> {
StartDocument,
EndDocument,
StartElement(StartElement<'a>),
EndElement(EndElement<'a>),
Characters(&'a str),
Reference(Reference<'a>),
StartComment,
Comment(&'a str),
EndComment,
StartCdataSection,
Cdata(&'a str),
EndCdataSection,
DocumentTypeDeclaration(&'a str),
ProcessingInstruction(&'a str),
XmlDeclaration(&'a str),
Whitespace(&'a str),
}