Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5949585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:16:14+00:00 2026-05-22T17:16:14+00:00

I want to get access to the data of an XML file like <?xml

  • 0

I want to get access to the data of an XML file like

<?xml version="1.0"?>
<MY>
  <Foo id="1" name="test">
    <Argument name="a" />
  </Foo>
  <Foo id="2" name="test2">
    <Argument name="a" />
    <Argument name="b" />
  </Foo>
  <Other id="2" name="someOther"/>
</MY>

I want e.g. to read out each Foo with its Arguments, how can I do this with Haskell? (I would like to use the HaXml module)

I don’t know where to start.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:16:15+00:00Added an answer on May 22, 2026 at 5:16 pm

    I cannot find up to date documentation and examples for haXml.

    There is however some documentation for HXT available.
    I know that’s probably an overkill for your example, but anyway.

    If you want to use tagsoup, perhaps the following answers might help:
    xml-tree parser (Haskell) for graph-library
    In Haskell how do you extract strings from an XML document?

    Here is the documentation an examples for 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

    Now the code using HXT.
    (warning I am not sure if this is the correct way)

    I followed the tutorial:
    http://www.haskell.org/haskellwiki/HXT/Conversion_of_Haskell_data_from/to_XML

    you need your xml file as “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 ()
    

    RESULT (you need you xml example as “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"}]}])]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get access to the data-global-id value in the following markup and
I want to access data (xml, to be specific) in different filepaths, depending on
I want to get xml data from free.worldweatheronline.com I tried in flollowing way:- <fx:Script>
I am trying to import an XML file into MS Access 2003, through File>Get
I want to to get the access token from LinkedIn. First I send the
Using Access 2003 I want to get a table value from the two databases
i want to access or get the class which is present in different project.How
when I want to retrieve date from access , I get an exception error
What I want: get a xml from the AppData to use What I code
Basically I want get data I already have accessed from javascript and passing it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.