|
|
@ -136,62 +136,37 @@ impl<R: BufRead> Iterator for RdfXmlIterator<R> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Read more XML
|
|
|
|
//Read more XML
|
|
|
|
let (namespace, event) = match self |
|
|
|
match self |
|
|
|
.reader |
|
|
|
.reader |
|
|
|
.read_namespaced_event(&mut buffer, &mut self.namespace_buffer) |
|
|
|
.read_namespaced_event(&mut buffer, &mut self.namespace_buffer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Ok((Some(namespace), event)) => { |
|
|
|
Ok((_, event)) => match event { |
|
|
|
(Some(self.reader.decode(namespace).to_string()), event) |
|
|
|
Event::Start(event) => { |
|
|
|
} |
|
|
|
if let Err(error) = self.parse_start_event(&event) { |
|
|
|
Ok((None, event)) => (None, event), |
|
|
|
return Some(Err(error)); |
|
|
|
Err(error) => return Some(Err(error.into())), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match event { |
|
|
|
|
|
|
|
Event::Start(event) => { |
|
|
|
|
|
|
|
let uri = match namespace { |
|
|
|
|
|
|
|
Some(namespace) => { |
|
|
|
|
|
|
|
Url::parse(&(namespace + &self.reader.decode(&event.local_name()))) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
None => Url::parse(&self.reader.decode(&event.name())), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
let uri = match uri { |
|
|
|
|
|
|
|
Ok(uri) => uri, |
|
|
|
|
|
|
|
Err(error) => return Some(Err(error.into())), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
if let Err(error) = self.parse_start_event(&event, uri) { |
|
|
|
|
|
|
|
return Some(Err(error)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Event::Text(event) => { |
|
|
|
Event::Text(event) => { |
|
|
|
if let Err(error) = self.parse_text_event(&event) { |
|
|
|
if let Err(error) = self.parse_text_event(&event) { |
|
|
|
return Some(Err(error)); |
|
|
|
return Some(Err(error)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Event::End(event) => { |
|
|
|
Event::End(event) => { |
|
|
|
if let Err(error) = self.parse_end_event(&event) { |
|
|
|
if let Err(error) = self.parse_end_event(&event) { |
|
|
|
return Some(Err(error)); |
|
|
|
return Some(Err(error)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Event::Eof => return None, |
|
|
|
Event::Eof => return None, |
|
|
|
_ => (), |
|
|
|
_ => (), |
|
|
|
}, |
|
|
|
|
|
|
|
Err(error) => return Some(Err(error.into())), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
fn read_next_event<'a, R: BufRead>(reader: &'a mut Reader<R>, namespace_buffer: &mut Vec<u8>) -> Result<(Option<String>, Event<'a>)> { |
|
|
|
|
|
|
|
let mut buffer = Vec::default(); |
|
|
|
|
|
|
|
Ok(match reader.read_namespaced_event(&mut buffer, namespace_buffer)? { |
|
|
|
|
|
|
|
(Some(namespace), event) => (Some(reader.decode(namespace).to_string()), event), |
|
|
|
|
|
|
|
(None, event) => (None, event) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl<R: BufRead> RdfXmlIterator<R> { |
|
|
|
impl<R: BufRead> RdfXmlIterator<R> { |
|
|
|
fn parse_start_event(&mut self, event: &BytesStart, uri: Url) -> Result<()> { |
|
|
|
fn parse_start_event(&mut self, event: &BytesStart) -> Result<()> { |
|
|
|
#[derive(PartialEq, Eq)] |
|
|
|
#[derive(PartialEq, Eq)] |
|
|
|
enum RdfXmlParseType { |
|
|
|
enum RdfXmlParseType { |
|
|
|
Default, |
|
|
|
Default, |
|
|
@ -208,6 +183,8 @@ impl<R: BufRead> RdfXmlIterator<R> { |
|
|
|
PropertyElt { subject: NamedOrBlankNode }, |
|
|
|
PropertyElt { subject: NamedOrBlankNode }, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let uri = self.resolve_tag_name(event.name())?; |
|
|
|
|
|
|
|
|
|
|
|
//We read attributes
|
|
|
|
//We read attributes
|
|
|
|
let mut language = String::default(); |
|
|
|
let mut language = String::default(); |
|
|
|
let mut base_uri = None; |
|
|
|
let mut base_uri = None; |
|
|
@ -234,7 +211,7 @@ impl<R: BufRead> RdfXmlIterator<R> { |
|
|
|
base_uri = Some(self.resolve_uri(&attribute.unescaped_value()?, &None)?) |
|
|
|
base_uri = Some(self.resolve_uri(&attribute.unescaped_value()?, &None)?) |
|
|
|
} |
|
|
|
} |
|
|
|
key if !key.starts_with(b"xml") => { |
|
|
|
key if !key.starts_with(b"xml") => { |
|
|
|
let attribute_url = self.resolve_q_name(key)?; |
|
|
|
let attribute_url = self.resolve_attribute_name(key)?; |
|
|
|
if attribute_url == *RDF_ID { |
|
|
|
if attribute_url == *RDF_ID { |
|
|
|
let mut id = Vec::with_capacity(attribute.value.len() + 1); |
|
|
|
let mut id = Vec::with_capacity(attribute.value.len() + 1); |
|
|
|
id.push(b'#'); |
|
|
|
id.push(b'#'); |
|
|
@ -417,8 +394,19 @@ impl<R: BufRead> RdfXmlIterator<R> { |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn resolve_q_name(&self, qname: &[u8]) -> Result<Url> { |
|
|
|
fn resolve_tag_name(&self, qname: &[u8]) -> Result<Url> { |
|
|
|
let (namespace, local_name) = self.reader.resolve_namespace(qname, &self.namespace_buffer); |
|
|
|
let (namespace, local_name) = self.reader.event_namespace(qname, &self.namespace_buffer); |
|
|
|
|
|
|
|
self.resolve_ns_name(namespace, local_name) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn resolve_attribute_name(&self, qname: &[u8]) -> Result<Url> { |
|
|
|
|
|
|
|
let (namespace, local_name) = self |
|
|
|
|
|
|
|
.reader |
|
|
|
|
|
|
|
.attribute_namespace(qname, &self.namespace_buffer); |
|
|
|
|
|
|
|
self.resolve_ns_name(namespace, local_name) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn resolve_ns_name(&self, namespace: Option<&[u8]>, local_name: &[u8]) -> Result<Url> { |
|
|
|
Ok(Url::parse( |
|
|
|
Ok(Url::parse( |
|
|
|
&(match namespace { |
|
|
|
&(match namespace { |
|
|
|
Some(namespace) => self.reader.decode(namespace) + self.reader.decode(local_name), |
|
|
|
Some(namespace) => self.reader.decode(namespace) + self.reader.decode(local_name), |
|
|
|