UweSchmidt / hxt

Haskell XML Toolbox
http://www.fh-wedel.de/~si/HXmlToolbox/index.html
124 stars 35 forks source link

Question: Using hxt-xpath to find matching substrings #98

Open ivanperez-keera opened 8 months ago

ivanperez-keera commented 8 months ago

I have a couple of xpath expressions, I'd like to use them to write code similar to the following:

obtain :: String -> String -> String -> [(String, String)]
obtain xpathSelector1 xpathSelector2 xpathSelector3 xmlContents =
    map f selection1
  where
    f :: String -> (String, String) -- or something similar
    f x  (someFunctionFromHXT2 x xpathSelector2, someFunctionFromHXT2 x xpathSelector3))

    selection1 :: [String] -- or something similar
    selection1 = someFunctionFromHXT1 xmlContents xpathSelector1

I don't know their exact types, I understand some of these may be more complicated or live in a monad. I guess I'm looking for a function that, given an xpath expression and a string s to look into, it'll give me a list of strings, each of which represents a matching string within s.

I think someFunctionFromHXT2 is probable just head . someFunctionFromHXT1 (or something similar).

I've spent some time navigating the API of HXT but I find it hard to search for what I'm looking for.

I'm able to get selection1 all concatenated as one string (that is, selection1 :: String), but I'm not able to get it as a list of strings. I need to apply the sub-selection expressions individually.

Thanks!