gdritter repos xleb / master
Add preliminary XML namespace selectors Getty Ritter 6 years ago
1 changed file(s) with 16 addition(s) and 0 deletion(s). Collapse all Expand all
142142 -- matched.
143143 data Selector
144144 = SelByName String
145 | SelByNS String
146 | SelBoth Selector Selector
145147 | SelAny
146148 deriving (Eq, Show)
149
150 instance Monoid Selector where
151 mempty = SelAny
152 mappend = SelBoth
147153
148154 instance GHC.IsString Selector where
149155 fromString = SelByName
152158 toPred SelAny _ = True
153159 toPred (SelByName n) el =
154160 XML.showQName (XML.elName el) == n
161 toPred (SelByNS n) el =
162 case XML.qPrefix (XML.elName el) of
163 Nothing -> False
164 Just p -> p == n
165 toPred (SelBoth s1 s2) el =
166 toPred s1 el && toPred s2 el
155167
156168 -- | Find an attribute on the current focus element and parse it to a
157169 -- value of type @t@. If the parse function fails, then this will fail
224236 byTag :: String -> Selector
225237 byTag = SelByName
226238
239 -- | Creates a 'Selector' which expects a specific namespace
240 byNamespace :: String -> Selector
241 byNamespace = SelByNS
242
227243 -- | Creates a 'Selector' which matches any possible child element.
228244 any :: Selector
229245 any = SelAny