Combining requireAttr and ignoreAttrs in xml-conduit

112 views Asked by At

I'm using Text.XML.Stream.Parse from xml-conduit to parse a large XML file.

My inner parser looks like this:

parseUserRow = tagName "row" (requireAttr "name") $ \name -> do -- [....]

When running it, I get a long error message like this:

xmltest.hs: UnparsedAttributes -- [...]

How can I resolve this issue?

Note: This question was answered by the asker immediately so it intentionally does not show any research effort.

1

There are 1 answers

0
Uli Köhler On BEST ANSWER

The ignoreAttrs documentation explicitly states that it shall be run after requireAttr.

The only question is how to combine these.

AttrParser has a Control.Applicative instance. Therefore you can combine it with one of the Applicative operators.

Note that while requireAttr <tagname> has the value type AttrParser Text, ignoreÀttrs has the no-value-type AttrParser (). This means, you can't use the <*> operator.

<*, however, is suitable for that purpose.

Example:

import Control.Applicative ((<*))

parseMyTag = tagName "mytag" (requireAttr "name" <* ignoreAttrs) $ \name -> do -- [...]