Haskell XML - Get attribute value from node



I am making an XML parser in haskell. I have got the desired node using XPath, but I am confused that how can I get the attribute value of a node. Kindly assist me.


Here is my XML



xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root response=\"True\"><movie title=\"hulk\"/></root>"


I want to get 'title' attribute value.



{-# LANGUAGE Arrows, NoMonomorphismRestriction #-}
import Text.XML.HXT.Core
import Text.XML.HXT.XPath.Arrows



data movie = movie { title :: String } deriving (Show, Eq)

xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root response=\"True\"><movie title=\"hulk\"/></root>"

main :: IO ()
main = do
runX $ readString [] xml
>>>
root [] [ selem "values" [getXPathTrees "root/movie"]]
>>>
writeDocument [withIndent yes] "out.xml"
return ()

No comments:

Post a Comment