Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
osmxml helper
fn parse_relation(&mut self, attrs: sax::Attributes) -> ParseResult {
let id = try!(self.parse_int_attr("id", attrs));
let mut tags = HashMap::new();
let mut members = Vec::new();
try!(helper(self, "relation", |name, attrs, osm| {
match name.as_slice() {
"member" => members.push(try!(osm.parse_member(attrs))),
"tag" => try!(osm.parse_tag(attrs, &mut tags)),
_ => return Err(ParseErr(format!("Relations can only have members and tags. Got {}",name)))
self.elements.insert(id, Relation{id: id, members: members, tags: tags});
fn helper(osm: &mut Osm, tag: &'static str, c: |String, sax::Attributes, &mut Osm| -> ParseResult) -> ParseResult {
for event in osm.parser.iter() {
match event {
Ok(sax::StartElement(name, attrs)) => try!(c(name, attrs, osm)),
Ok(sax::EndElement(name)) => {
if name.as_slice() == tag.as_slice() {
return Err(ParseErr(format!(
"Expecting tag to end. Instead got a {}", name)));
_ => ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.