hxt

xml-tree parser (Haskell) for graph-library

自闭症网瘾萝莉.ら 提交于 2019-12-11 03:58:53
问题 I'm writing a library for working with graphs. The primary task - parsing xml-tree. The tree looks like <graph nodes=4 arcs=5> <node id=1 /> <node id=2 /> <node id=3 /> <node id=4 /> <arc from=1 to=2 /> <arc from=1 to=3 /> <arc from=1 to=4 /> <arc from=2 to=4 /> <arc from=3 to=4 /> </graph> Structure for storing: type Id = Int data Node = Node Id deriving (Show) data Arc = Arc Id Id deriving (Show) data Graph = Graph { nodes :: [Node], arcs :: [Arc]} How to write data from the xml file into

Arrow to add one element at a time

点点圈 提交于 2019-12-11 02:54:40
问题 This question is about HXT, but I guess it's applicable to conception of ArrowPlus in general. Consider the following program: module Main (main) where import Text.XML.HXT.Core import Control.Monad (void) main :: IO () main = void $ runX $ root [] [foo] >>> writeDocument [withIndent yes] "test.xml" foo :: ArrowXml a => a XmlTree XmlTree foo = selem "foo" [bar >>> bar >>> bar] bar :: ArrowXml a => a XmlTree XmlTree bar = this <+> eelem "bar" Can you tell what will be saved in test.xml ? My

Parsing multiple child nodes in Haskell with HXT

╄→гoц情女王★ 提交于 2019-12-10 21:26:14
问题 I needed to parse an XML file in Haskell, so I chose HXT. I like it so far, but I'm having trouble figuring out how to do one thing. The file I'm parsing contains information as a config file. It has a structure similar to <clients> <client> <name>SomeName</name> <info>MoreInfo</info> <table> <row> <name>rowname1</name> <value>rowvalue1</value> </row> <row> <name>rowname2</name> <value>rowvalue2</value> </row> </table> </client> ... </clients> This markup format makes me cringe, but it's what

HXT ignoring HTML DTD, replacing it with XML DTD

不羁岁月 提交于 2019-12-10 15:04:53
问题 I'm having a bit of trouble figuring out why HXT is replacing my DTD's. Firstly, here is my input file to be parsed: <!DOCTYPE html> <html> <head> <title>foo</title> </head> <body> <h1>foo</h1> </body> </html> and this is the output that I get: <?xml version="1.0" encoding="US-ASCII"?> <html> <head> <title>foo</title> </head> <body> <h1>foo</h1> </body> </html> Finally, here is a simplified version of the arrows I'm using: start (App src dest) = runX $ readDocument [ withValidate no ,

Is it possible to use Text or ByteString on HXT in Haskell?

橙三吉。 提交于 2019-12-08 16:37:28
问题 I think HXT, a XML/HTML processing library in Haskell, has really flexible and powerful methods for traversing and manipulating DOM trees by Arrows. http://adit.io/posts/2012-04-14-working_with_HTML_in_haskell.html It seems, however, HXT has only String representation for DOM node contents. http://hackage.haskell.org/packages/archive/hxt/9.1.6/doc/html/Text-XML-HXT-DOM-TypeDefs.html#t:XNode Is it possible to use either of ByteString or Text for HXT? Text is preferred since I am using HXT with

How do i replace Nodes in HXT?

天大地大妈咪最大 提交于 2019-12-07 01:15:42
问题 Given a sample xml file: <root> <tag attr="value">Content</tag> <tag attr="value2">Content</tag> </root> how do i replace every tag with a different tag so i get a different file: <root> <tag2 attr2="value"/> <tag2 attr2="value2"/> </root> The documentation [1] seems to use Filters, is there a way to accomplish this with arrows alone? Update i am now at the point where i can replace a node like this: runX $ readDocument [] "in.xml" >>> processTopDown( (eelem "tag2" += sattr "attr2" "XXX" )

Group html table rows with HXT in Haskell

巧了我就是萌 提交于 2019-12-06 13:31:29
问题 I want to process a (very poorly defined) html, which has the information grouped in pairs of rows, like this: <html> <body> <table> <tr> <td> <font > <a href="a">ABC</a></font> </td> </tr> <tr> <td height="50"> <font>When:</font><font>19-1-2013</font> <b><font>  </font></b> <font>Where:</font><font>Here</font> <font>Who:</font><font>Me</font> </td> </tr> <tr> <td> <font > <a href="b">EFG</a> </font> </td> </tr> <tr> <td height="50"> <font>When:</font><font>19-2-2013</font> <b><font>  </font>

How do i output XMLTrees in HXT?

别说谁变了你拦得住时间么 提交于 2019-12-06 08:52:50
I am trying to extract tags from a xml file and write each one to a seperate file based on an attribute. The extraction part isn't that hard: *Main> ifs <- runX ( readDocument [withCurl [],withExpat yes] "file.xml" >>> getElement "TagName" >>> getAttrValue "Name" &&& this) *Main> :t ifs ifs :: [(String, XmlTree)] I tried to map writeDocument over the second entries but had no sucess. I understand that i have to get it back into the IO Monad somehow ... but have no idea on how to achieve this. for testing purposes i have extracted on of those XmlTrees from the result: *Main> let x = (map snd

How do i replace Nodes in HXT?

时光怂恿深爱的人放手 提交于 2019-12-05 04:47:23
Given a sample xml file: <root> <tag attr="value">Content</tag> <tag attr="value2">Content</tag> </root> how do i replace every tag with a different tag so i get a different file: <root> <tag2 attr2="value"/> <tag2 attr2="value2"/> </root> The documentation [1] seems to use Filters, is there a way to accomplish this with arrows alone? Update i am now at the point where i can replace a node like this: runX $ readDocument [] "in.xml" >>> processTopDown( (eelem "tag2" += sattr "attr2" "XXX" ) `when` (isElem >>> hasName "tag") ) >>> writeDocument [] "test.xml" but i have no idea on how to get the

Group html table rows with HXT in Haskell

大城市里の小女人 提交于 2019-12-04 19:56:05
I want to process a (very poorly defined) html, which has the information grouped in pairs of rows, like this: <html> <body> <table> <tr> <td> <font > <a href="a">ABC</a></font> </td> </tr> <tr> <td height="50"> <font>When:</font><font>19-1-2013</font> <b><font>  </font></b> <font>Where:</font><font>Here</font> <font>Who:</font><font>Me</font> </td> </tr> <tr> <td> <font > <a href="b">EFG</a> </font> </td> </tr> <tr> <td height="50"> <font>When:</font><font>19-2-2013</font> <b><font>  </font></b> <font>Where:</font><font>There</font> <font>Who:</font><font>You</font> </td> </tr> <tr> <td>