No puedo encontrar documentación actualizada y ejemplos para haXml.
Sin embargo, hay documentación disponible para HXT. Sé que es probablemente una exageración para su ejemplo, pero de todos modos.
Si desea utilizar tagsoup, tal vez las siguientes respuestas podrían ayudar:
xml-tree parser (Haskell) for graph-library
In Haskell how do you extract strings from an XML document?
Aquí está la documentación un ejemplo para HXT:
http://www.haskell.org/haskellwiki/HXT/Conversion_of_Haskell_data_from/to_XML
http://www.haskell.org/haskellwiki/HXT
http://www.haskell.org/haskellwiki/HXT/Practical
http://en.wikibooks.org/wiki/Haskell/XML
Ahora el código usando HXT. (advirtiendo que no estoy seguro de si este es el camino correcto)
he seguido el tutorial: http://www.haskell.org/haskellwiki/HXT/Conversion_of_Haskell_data_from/to_XML
necesita que su fichero XML como "data.xml"
import Data.Map (Map, fromList, toList)
import Text.XML.HXT.Core
type Foos = Map String [Foo]
data Foo = Foo
{
fooId :: String
, fooName :: String
, arguments :: [Argument]
}
deriving (Show, Eq)
data Argument = Argument
{ argName :: String
}
deriving (Show, Eq)
instance XmlPickler Foo where
xpickle = xpFoo
instance XmlPickler Argument where
xpickle = xpArgument
-- WHY do we need this?? no clue
instance XmlPickler Char where
xpickle = xpPrim
-- this could be wrong
xpFoos :: PU Foos
xpFoos
= xpWrap (fromList
, toList
) $
xpList $
xpElem "MY" $
xpickle
xpFoo :: PU Foo
xpFoo
= xpElem "Foo" $
xpWrap (uncurry3 Foo
, \ f -> (fooId f
, fooName f
, arguments f
)
) $
xpTriple (xpAttr "id" xpText)
(xpAttr "name" xpText)
(xpList xpickle)
xpArgument :: PU Argument
xpArgument
= xpElem "Argument" $
xpWrap (\ ((a)) -> Argument a
, \ t -> (argName t)
) $
(xpAttr "name" xpText)
main :: IO()
main
= do
runX (xunpickleDocument xpFoos
[ withValidate no
, withTrace 1
, withRemoveWS yes
, withPreserveComment no
] "data.xml"
>>>
arrIO (\ x -> do {print x ; return x})
)
return()
resultado (que necesita ejemplo xml como "data.xml"):
-- (1) getXmlContents
-- (1) readDocument: "data.xml" (mime type: "text/xml") will be processed
-- (1) readDocument: "data.xml" processed
fromList [("",[Foo {fooId = "1", fooName = "test", arguments = [Argument {argName = "a"}]},
Foo {fooId = "2", fooName = "test2", arguments = [Argument {argName = "a"},
Argument {argName = "b"}]}])]
Podría explicar cómo hacerlo con tagsoup? – ewggwegw
Hay algunos [ejemplos] (http://community.haskell.org/~ndm/darcs/tagsoup/tagsoup.htm) vinculados en la [página de etiquetas] (http://community.haskell.org/~ndm/ tagoup /) – atomicules