Skip to content

Instantly share code, notes, and snippets.

@k16shikano
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k16shikano/faa43d2b3963b1202fa9 to your computer and use it in GitHub Desktop.
Save k16shikano/faa43d2b3963b1202fa9 to your computer and use it in GitHub Desktop.
HXTでbodyタグだけテキストを書き換え
{-# LANGUAGE Arrows, FlexibleContexts #-}
import Text.XML.HXT.Core
import Text.XML.HXT.Arrow.XmlArrow
main :: IO [String]
main = do
runX (readString [ ] "<html><head>foo</head><body><p>bar</p></body></html>"
>>>
processBottomUp
(processBottomUp
((changeText ("hoge"++)) `when` isText)
`when` hasName "body")
>>>
writeDocumentToString [ ]
)
{-# LANGUAGE Arrows, FlexibleContexts #-}
import Text.XML.HXT.Core
import Text.XML.HXT.Arrow.XmlArrow
main :: IO [String]
main = do
runX (readString [ ] "<html><head>foo</head><body><p>foo</p><p class=\"sty\">bar</p></body></html>"
>>>
processBottomUp
(processBottomUp
(choiceA [ neg (hasAttrValue "class" (=="sty"))
:-> processChildren (changeText ("hoge"++) `when` isText)
, this
:-> this])
`when` hasName "body")
>>>
writeDocumentToString [ ]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment