Fragile and verbose code using xml-conduit

rustyfangs

New Member
I built a GPX parser using XML-conduit and have had issues with overly verbose and fragile code for identifying elements and skipping unwanted tags.Identifying elements (a minor annoyance)I am explicitly ignoring name space by comparing only \[code\]nameLocalName\[/code\]s. I guess the correct way is to hardcode the right namespace(s) into the program and have a helper construct my element names for comparison in the \[code\]tag*\[/code\] functions? This is slightly annoying as I must support at least two different name spaces (GPX 1.1 and 1.0) that are sufficiently similar that they require no code changes for my uses.Skipping elementsGPX is largish and the set of custom extensions is larger. Because the tool I'm building needs limited information I decided to ignore particular tags along with all of their sub-elements. For example:\[code\]<trkpnt lat="45.19843" lon="-122.428"> <ele>4</ele> <time>...</time> <extensions> ... </extensions></trkpnt>\[/code\]To ignore \[code\]extensions\[/code\] and similar tags with numerous sub elements I made a sink that would consume elements till the end element \[code\]Event\[/code\]:\[code\]skipTagAndContents :: (MonadThrow m) => Text -> Sink Event m (Maybe ())skipTagAndContents n = tagPredicate ((== n) . nameLocalName) ignoreAttrs (const $ many (skipElements n) >> return ())skipElements t = do x <- await case x of Just (EventEndElement n) | nameLocalName n == t -> Done x Nothing Nothing -> Done x Nothing _ -> return (Just ())\[/code\]It seems there should be a \[code\]tag*\[/code\] variant that will do this for me (succeed without all children being consumed) but that fact that there isn't suggests I am missing a simple combinator or should send a patch - which is it?
 
Back
Top